From d52dcb253c63a153632bfee5f269dd411dcd8e96 Mon Sep 17 00:00:00 2001 From: David Howden Date: Fri, 20 Nov 2020 18:04:54 +1100 Subject: [PATCH] fix panic on invalid input Fixes #79 --- id3v2frames.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/id3v2frames.go b/id3v2frames.go index f0c363e..8397eba 100644 --- a/id3v2frames.go +++ b/id3v2frames.go @@ -452,21 +452,24 @@ func (t Comm) String() string { // Description $00 (00) // Value 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])