Skip to content

Commit

Permalink
fix panic on invalid input
Browse files Browse the repository at this point in the history
Fixes #79
  • Loading branch information
dhowden committed Nov 20, 2020
1 parent a922134 commit d52dcb2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions id3v2frames.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,21 +452,24 @@ func (t Comm) String() string {
// Description <text string according to encoding> $00 (00)
// Value <text string according to encoding>
func readTextWithDescrFrame(b []byte, hasLang bool, encoded bool) (*Comm, error) {
if len(b) == 0 {
return nil, errors.New("error decoding tag description text: invalid encoding")
}
enc := b[0]
b = b[1:]

c := &Comm{}
if hasLang {
if len(b) < 3 {
return nil, fmt.Errorf("hasLang set but not enough data for language information")
return nil, errors.New("hasLang set but not enough data for language information")
}
c.Language = string(b[:3])
b = b[3:]
}

descTextSplit := dataSplit(b, enc)
if len(descTextSplit) < 1 {
return nil, fmt.Errorf("error decoding tag description text: invalid encoding")
if len(descTextSplit) == 0 {
return nil, errors.New("error decoding tag description text: invalid encoding")
}

desc, err := decodeText(enc, descTextSplit[0])
Expand Down

0 comments on commit d52dcb2

Please sign in to comment.