From 1582ebc2a4525aeaccf7138ffd37e56f5117e49e Mon Sep 17 00:00:00 2001 From: David Howden Date: Wed, 7 Feb 2018 18:32:42 +1100 Subject: [PATCH] mp4: fix panic on invalid encoding Fixes #32 --- mp4.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mp4.go b/mp4.go index b823c70..9071f89 100644 --- a/mp4.go +++ b/mp4.go @@ -133,6 +133,10 @@ func (m metadataMP4) readAtomData(r io.ReadSeeker, name string, size uint32) err return err } + if len(b) < 8 { + return fmt.Errorf("invalid encoding: expected at least %d bytes, got %d", 8, len(b)) + } + // "data" + size (4 bytes each) b = b[8:] @@ -222,7 +226,7 @@ func readCustomAtom(r io.ReadSeeker, size uint32) (string, uint32, error) { } if len(b) < 4 { - return "", 0, fmt.Errorf("expected at least %d bytes, got %d", 4, len(b)) + return "", 0, fmt.Errorf("invalid encoding: expected at least %d bytes, got %d", 4, len(b)) } subNames[subName] = string(b[4:])