From 53ee65d2aee8eadf4a15b02b7af98ecf26e1073c Mon Sep 17 00:00:00 2001 From: David Howden Date: Fri, 20 Nov 2020 06:21:26 +1100 Subject: [PATCH] be more cautious with language parsing Relates to #76 --- id3v2.go | 2 +- id3v2frames.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/id3v2.go b/id3v2.go index d4c6838..cb6c662 100644 --- a/id3v2.go +++ b/id3v2.go @@ -363,7 +363,7 @@ func readID3v2Frames(r io.Reader, offset uint, h *id3v2Header) (map[string]inter case name == "COMM" || name == "COM" || name == "USLT" || name == "ULT": t, err := readTextWithDescrFrame(b, true, true) // both lang and enc if err != nil { - return nil, err + return nil, fmt.Errorf("could not read %q (%q): %v", name, rawName, err) } result[rawName] = t diff --git a/id3v2frames.go b/id3v2frames.go index a92afa1..569a609 100644 --- a/id3v2frames.go +++ b/id3v2frames.go @@ -457,6 +457,9 @@ func readTextWithDescrFrame(b []byte, hasLang bool, encoded bool) (*Comm, error) c := &Comm{} if hasLang { + if len(b) < 3 { + return nil, fmt.Errorf("hasLang set but not enough data for language information") + } c.Language = string(b[:3]) b = b[3:] }