From 6216b2ed1fcd0b06a9e0b3ae74e5373a8cccd114 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Tue, 15 Sep 2026 00:06:58 +0200 Subject: track: bound malformed sample tables --- track/fuzz_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 track/fuzz_test.go (limited to 'track/fuzz_test.go') diff --git a/track/fuzz_test.go b/track/fuzz_test.go new file mode 100644 index 0000000..313c901 --- /dev/null +++ b/track/fuzz_test.go @@ -0,0 +1,43 @@ +package track_test + +import ( + "os" + "testing" + + "github.com/tetsuo/mp4" + "github.com/tetsuo/mp4/track" +) + +const fuzzSample = "../test-data/big-buck-bunny-480p-30sec.mp4" + +// FuzzParseTracks feeds arbitrary bytes to the moov parser. A malformed moov +// must return an error rather than panic. The seeds include a real moov when +// available and a moov holding a truncated mvhd, which reaches a field +// extractor with fewer bytes than the box layout requires. +func FuzzParseTracks(f *testing.F) { + if data, err := os.ReadFile(fuzzSample); err == nil { + r := mp4.NewReader(data) + for r.Next() { + if r.Type() == mp4.TypeMoov { + f.Add(append([]byte(nil), r.RawBox()...)) + break + } + } + } + f.Add([]byte(nil)) + f.Add([]byte{0, 0, 0, 8, 'm', 'o', 'o', 'v'}) + f.Add([]byte{ + 0, 0, 0, 0x18, 'm', 'o', 'o', 'v', + 0, 0, 0, 0x10, 'm', 'v', 'h', 'd', 0, 0, 0, 0, 0, 0, 0, 0, + }) + + f.Fuzz(func(t *testing.T, data []byte) { + tracks, _, _, err := track.ParseTracks(data) + if err != nil { + return + } + for _, tr := range tracks { + _ = tr.Codec() + } + }) +} -- cgit v1.3.1