Check versions before using data length indicator (#66)

* id3v2: Read and use frame data length indicator

* id3v2: only use data length indicator for 2.4

Co-authored-by: Mattias Wadman <mattias.wadman@gmail.com>
This commit is contained in:
David Howden 2020-04-11 12:20:04 +10:00 committed by GitHub
parent 7e5c04fecc
commit 869a70545f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@
package tag
import (
"errors"
"fmt"
"io"
"regexp"
@ -269,11 +270,34 @@ func readID3v2Frames(r io.Reader, offset uint, h *id3v2Header) (map[string]inter
if flags != nil {
if flags.Compression {
_, err = read7BitChunkedUint(r, 4) // read 4
if err != nil {
switch h.Version {
case ID3v2_3:
// No data length indicator defined.
if _, err := read7BitChunkedUint(r, 4); err != nil { // read 4
return nil, err
}
size -= 4
case ID3v2_4:
// Must have a data length indicator (to give the size) if compression is enabled.
if !flags.DataLengthIndicator {
return nil, errors.New("compression without data length indicator")
}
default:
return nil, fmt.Errorf("unsupported compression flag used in %v", h.Version)
}
}
if flags.DataLengthIndicator {
if h.Version == ID3v2_3 {
return nil, fmt.Errorf("data length indicator set but not defined for %v", ID3v2_3)
}
size, err = read7BitChunkedUint(r, 4)
if err != nil { // read 4
return nil, err
}
size -= 4
}
if flags.Encryption {