Skip to content

Commit cfc0783

Browse files
erictobbee
authored andcommitted
fix: ensure ssix box is large enough to read
1 parent fa56081 commit cfc0783

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

mp4/fuzz_test.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import (
99
"errors"
1010
"io"
1111
"os"
12+
"path/filepath"
1213
"runtime"
13-
"strings"
1414
"testing"
1515
"time"
16+
17+
"github.com/Eyevinn/mp4ff/bits"
1618
)
1719

1820
func monitorMemory(ctx context.Context, t *testing.T, memoryLimit int) {
@@ -43,8 +45,18 @@ func FuzzDecodeBox(f *testing.F) {
4345
f.Fatal(err)
4446
}
4547

48+
validExts := map[string]bool{
49+
".mp4": true,
50+
".m4s": true,
51+
".cmfv": true,
52+
}
53+
4654
for _, entry := range entries {
47-
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".mp4") {
55+
if entry.IsDir() {
56+
continue
57+
}
58+
59+
if validExts[filepath.Ext(entry.Name())] {
4860
testData, err := os.ReadFile("testdata/" + entry.Name())
4961
if err != nil {
5062
f.Fatal(err)
@@ -59,7 +71,6 @@ func FuzzDecodeBox(f *testing.F) {
5971
monitorMemory(ctx, t, 500*1024*1024) // 500MB
6072

6173
r := bytes.NewReader(b)
62-
6374
var pos uint64 = 0
6475
for {
6576
box, err := DecodeBox(pos, r)
@@ -73,5 +84,20 @@ func FuzzDecodeBox(f *testing.F) {
7384
}
7485
pos += box.Size()
7586
}
87+
88+
pos = 0
89+
sr := bits.NewFixedSliceReader(b)
90+
for {
91+
box, err := DecodeBoxSR(pos, sr)
92+
if err != nil {
93+
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
94+
break
95+
}
96+
}
97+
if box == nil {
98+
break
99+
}
100+
pos += box.Size()
101+
}
76102
})
77103
}

mp4/ssix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func DecodeSsixSR(hdr BoxHeader, startPos uint64, sr bits.SliceReader) (Box, err
7070
Version: version,
7171
Flags: versionAndFlags & flagsMask,
7272
}
73+
if hdr.Size < 16 {
74+
return nil, fmt.Errorf("ssix: box is too small")
75+
}
7376
subSegmentCount := sr.ReadUint32()
7477
sizeLeft := hdr.Size - 16
7578
if subSegmentCount > uint32(sizeLeft/8) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go test fuzz v1
2+
[]byte("\x00\x00\x00\bssix\x00\x00\x00\x0100,\x00")

0 commit comments

Comments
 (0)