diff --git a/util.go b/util.go index ff9c4f1..7ffd0f8 100644 --- a/util.go +++ b/util.go @@ -74,8 +74,10 @@ func read7BitChunkedInt(r io.Reader, n int) (int, error) { return get7BitChunkedInt(b), nil } -func readInt32LittleEndian(r io.Reader) (int, error) { - var n int32 - err := binary.Read(r, binary.LittleEndian, &n) - return int(n), err +func readUint32LittleEndian(r io.Reader) (uint32, error) { + b, err := readBytes(r, 4) + if err != nil { + return 0, err + } + return binary.LittleEndian.Uint32(b), nil } diff --git a/vorbis.go b/vorbis.go index 9f5ecb8..a140c4a 100644 --- a/vorbis.go +++ b/vorbis.go @@ -25,32 +25,28 @@ type metadataVorbis struct { } func (m *metadataVorbis) readVorbisComment(r io.Reader) error { - vendorLen, err := readInt32LittleEndian(r) + vendorLen, err := readUint32LittleEndian(r) if err != nil { return err } - if vendorLen < 0 { - return fmt.Errorf("invalid encoding: expected positive length, got %d", vendorLen) - } - - vendor, err := readString(r, vendorLen) + vendor, err := readString(r, int(vendorLen)) if err != nil { return err } m.c["vendor"] = vendor - commentsLen, err := readInt32LittleEndian(r) + commentsLen, err := readUint32LittleEndian(r) if err != nil { return err } - for i := 0; i < commentsLen; i++ { - l, err := readInt32LittleEndian(r) + for i := uint32(0); i < commentsLen; i++ { + l, err := readUint32LittleEndian(r) if err != nil { return err } - s, err := readString(r, l) + s, err := readString(r, int(l)) if err != nil { return err }