aboutsummaryrefslogtreecommitdiff
path: root/track/fuzz_test.go
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-09-15 00:06:58 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-09-15 00:06:58 +0200
commit6216b2ed1fcd0b06a9e0b3ae74e5373a8cccd114 (patch)
tree2d4cba21bfe0f23b9ee469bb0cb46bab251857fa /track/fuzz_test.go
parent63391b66a7c5d10e84d4d8c64510e3620152dc26 (diff)
downloadmp4-6216b2ed1fcd0b06a9e0b3ae74e5373a8cccd114.tar.gz
mp4-6216b2ed1fcd0b06a9e0b3ae74e5373a8cccd114.zip
track: bound malformed sample tables
Diffstat (limited to 'track/fuzz_test.go')
-rw-r--r--track/fuzz_test.go43
1 files changed, 43 insertions, 0 deletions
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()
+ }
+ })
+}