vorbis: refactor integer decoding to use more clear naming

Relates to #56.
This commit is contained in:
David Howden 2019-11-21 00:19:27 +11:00
parent db0c67e351
commit f644c14784
2 changed files with 12 additions and 14 deletions

10
util.go
View File

@ -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
}

View File

@ -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
}