Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve fuzz tests #158

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions pkg/playlist/media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var casesMedia = []struct {
"#EXT-X-PROGRAM-DATE-TIME:2014-08-25T00:00:00Z\n" +
"#EXT-X-BITRATE:14213213\n" +
"#EXT-X-PART:DURATION=1.50000,URI=\"part1.mp4\",INDEPENDENT=YES\n" +
"#EXT-X-PART:DURATION=1.50000,URI=\"part2.mp4\"\n" +
"#EXT-X-PART:DURATION=1.50000,URI=\"part2.mp4\",BYTERANGE=456@123\n" +
"#EXTINF:3.00000,\n" +
"seg2.mp4\n" +
"#EXT-X-PART:DURATION=1.50000,URI=\"part3.mp4\",INDEPENDENT=YES\n" +
Expand All @@ -63,7 +63,7 @@ var casesMedia = []struct {
"#EXT-X-PROGRAM-DATE-TIME:2014-08-25T00:00:00Z\n" +
"#EXT-X-BITRATE:14213213\n" +
"#EXT-X-PART:DURATION=1.50000,URI=\"part1.mp4\",INDEPENDENT=YES\n" +
"#EXT-X-PART:DURATION=1.50000,URI=\"part2.mp4\"\n" +
"#EXT-X-PART:DURATION=1.50000,URI=\"part2.mp4\",BYTERANGE=456@123\n" +
"#EXTINF:3.00000,\n" +
"seg2.mp4\n" +
"#EXT-X-PART:DURATION=1.50000,URI=\"part3.mp4\",INDEPENDENT=YES\n" +
Expand Down Expand Up @@ -112,8 +112,10 @@ var casesMedia = []struct {
URI: "part1.mp4",
},
{
Duration: 1500 * time.Millisecond,
URI: "part2.mp4",
Duration: 1500 * time.Millisecond,
URI: "part2.mp4",
ByteRangeLength: uint64Ptr(456),
ByteRangeStart: uint64Ptr(123),
},
},
},
Expand Down Expand Up @@ -307,21 +309,13 @@ func TestMediaMarshal(t *testing.T) {
}

func FuzzMediaUnmarshal(f *testing.F) {
f.Add("#EXTM3U\n" +
"#EXT-X-SKIP:SKIPPED-SEGMENTS=aa\n")

f.Add("#EXTM3U\n" +
"#EXT-X-MAP:URI=\"init.mp4\",BYTERANGE=\n")
for _, ca := range casesMedia {
f.Add(ca.input)
}

f.Add("#EXTM3U\n" +
"#EXT-X-PART:DURATION=1.50000,URI=\"part3.mp4\",INDEPENDENT=YES,BYTERANGE=\n")

f.Add("#EXTM3U\n" +
"#EXT-X-PRELOAD-HINT:TYPE=PART,URI=\"part5.mp4\",BYTERANGE-START=43523,BYTERANGE-LENGTH=123\n")

f.Add("#EXTM3U\n" +
"#EXT-X-SERVER-CONTROL:CAN-BLOCK-RELOAD=YES,PART-HOLD-BACK=5.00000,CAN-SKIP-UNTIL=7.00000\n")

f.Fuzz(func(_ *testing.T, a string) {
var m Media
m.Unmarshal([]byte(a)) //nolint:errcheck
Expand Down
21 changes: 3 additions & 18 deletions pkg/playlist/multivariant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,28 +870,13 @@ func TestMultivariantMarshal(t *testing.T) {
}

func FuzzMultivariantUnmarshal(f *testing.F) {
f.Add("#EXTM3U\n" +
"#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"aud1\",LANGUAGE=\"en\",NAME=\"English\",AUTOSELECT=YES,DEFAULT=YES,CHANNELS=\"2\",URI=\"a1/prog_index.m3u8\"\n")
for _, ca := range casesMultivariant {
f.Add(ca.input)
}

f.Add("#EXTM3U\n" +
"#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"aud1\",LANGUAGE=\"en\",NAME=\"English\",AUTOSELECT=YES,DEFAULT=YES,CHANNELS=\"2\",URI=\"a1/prog_index.m3u8\",INSTREAM-ID=\"a\"\n")

f.Add("#EXTM3U\n" +
"#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,GROUP-ID=\"cc1\",LANGUAGE=\"en\",NAME=\"English\",AUTOSELECT=YES,DEFAULT=YES,INSTREAM-ID=\"CC1\"\n")

f.Add("#EXTM3U\n" +
"#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,GROUP-ID=\"cc1\",LANGUAGE=\"en\",NAME=\"English\",AUTOSELECT=YES,DEFAULT=YES,INSTREAM-ID=\"CC1\",URI=\"a\"\n")

f.Add("#EXTM3U\n" +
"#EXT-X-START:TIME-OFFSET=15.00000\n")

f.Add("#EXTM3U\n" +
"#EXT-X-START:TIME-OFFSET=15.00000\n")

f.Add("#EXTM3U\n" +
"#EXT-X-STREAM-INF:BANDWIDTH=2177116,AVERAGE-BANDWIDTH=2168183,CODECS=\"avc1.640020,mp4a.40.2\",RESOLUTION=960x540,FRAME-RATE=60.000,AUDIO=\"aud1\",SUBTITLES=\"sub1\",CLOSED-CAPTIONS=\"cc1\"\n" +
"v5/prog_index.m3u8\n")

f.Fuzz(func(_ *testing.T, a string) {
var m Multivariant
m.Unmarshal([]byte(a)) //nolint:errcheck
Expand Down
8 changes: 7 additions & 1 deletion pkg/playlist/playlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ func TestUnmarshal(t *testing.T) {
}

func FuzzPlaylistUnmarshal(f *testing.F) {
f.Add("#EXTINF:")
for _, ca := range casesMultivariant {
f.Add(ca.input)
}

for _, ca := range casesMedia {
f.Add(ca.input)
}

f.Fuzz(func(_ *testing.T, a string) {
Unmarshal([]byte(a)) //nolint:errcheck
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("#EXTM3U\n#EXT-X-BYTERANGE:0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("#EXTM3U\n#EXT-X-TARGETDURATION:1")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("#EXTM3U\n#EXT-X-MAP:BYTERANGE=")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("#EXTM3U\n#EXT-X-SKIP:SKIPPED-SEGMENTS=")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("#EXTM3U\n#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,GROUP-ID=0,URI=00")
Loading