improve fuzz tests (#591)

This commit is contained in:
Alessandro Ros
2024-08-01 11:56:52 +02:00
committed by GitHub
parent b160f5a614
commit e2d1e6dab4
56 changed files with 612 additions and 225 deletions

View File

@@ -33,3 +33,31 @@ func TestAV1DecEncoder(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, [][]byte{{0x01, 0x02, 0x03, 0x04}}, byts) require.Equal(t, [][]byte{{0x01, 0x02, 0x03, 0x04}}, byts)
} }
func FuzzUnmarshalAV1(f *testing.F) {
f.Fuzz(func(
_ *testing.T,
a bool,
b string,
c bool,
d string,
e bool,
f string,
) {
ma := map[string]string{}
if a {
ma["level-idx"] = b
}
if c {
ma["profile"] = d
}
if e {
ma["tier"] = f
}
Unmarshal("video", 96, "AV1/90000", ma) //nolint:errcheck
})
}

View File

@@ -1123,187 +1123,4 @@ func TestUnmarshalErrors(t *testing.T) {
_, err := Unmarshal("video", 96, "", map[string]string{}) _, err := Unmarshal("video", 96, "", map[string]string{})
require.Error(t, err) require.Error(t, err)
}) })
t.Run("mpeg-4 audio generic", func(t *testing.T) {
_, err := Unmarshal("audio", 96, "MPEG4-generic/48000/2", map[string]string{
"streamtype": "10",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MPEG4-generic/48000/2", map[string]string{
"mode": "asd",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MPEG4-generic/48000/2", map[string]string{
"profile-level-id": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MPEG4-generic/48000/2", map[string]string{
"config": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MPEG4-generic/48000/2", map[string]string{
"config": "0ab2",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MPEG4-generic/48000/2", map[string]string{
"sizelength": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MPEG4-generic/48000/2", map[string]string{
"indexlength": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MPEG4-generic/48000/2", map[string]string{
"indexdeltalength": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MPEG4-generic/48000/2", map[string]string{
"profile-level-id": "1",
"sizelength": "13",
"indexlength": "3",
"indexdeltalength": "3",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MPEG4-generic/48000/2", map[string]string{
"profile-level-id": "1",
"config": "1190",
"indexlength": "3",
"indexdeltalength": "3",
})
require.Error(t, err)
})
t.Run("mpeg-4 audio latm", func(t *testing.T) {
_, err := Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"profile-level-id": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"bitrate": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"cpresent": "0",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"config": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("audio", 96, "MP4A-LATM/48000/2", map[string]string{
"profile-level-id": "15",
"object": "2",
"cpresent": "0",
"sbr-enabled": "1",
})
require.Error(t, err)
})
t.Run("av1", func(t *testing.T) {
_, err := Unmarshal("video", 96, "AV1/90000", map[string]string{
"level-idx": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("video", 96, "AV1/90000", map[string]string{
"profile": "aaa",
})
require.Error(t, err)
_, err = Unmarshal("video", 96, "AV1/90000", map[string]string{
"tier": "aaa",
})
require.Error(t, err)
})
}
func FuzzUnmarshalH264(f *testing.F) {
f.Fuzz(func(_ *testing.T, sps string, pktMode string) {
Unmarshal("video", 96, "H264/90000", map[string]string{ //nolint:errcheck
"sprop-parameter-sets": sps,
"packetization-mode": pktMode,
})
})
}
func FuzzUnmarshalH265(f *testing.F) {
f.Fuzz(func(_ *testing.T, a, b, c, d string) {
Unmarshal("video", 96, "H265/90000", map[string]string{ //nolint:errcheck
"sprop-vps": a,
"sprop-sps": b,
"sprop-pps": c,
"sprop-max-don-diff": d,
})
})
}
func FuzzUnmarshalLPCM(f *testing.F) {
f.Fuzz(func(_ *testing.T, a string) {
Unmarshal("audio", 96, "L16/"+a, nil) //nolint:errcheck
})
}
func FuzzUnmarshalMPEG4Video(f *testing.F) {
f.Fuzz(func(_ *testing.T, a, b string) {
Unmarshal("video", 96, "MP4V-ES/90000", map[string]string{ //nolint:errcheck
"profile-level-id": a,
"config": b,
})
})
}
func FuzzUnmarshalOpus(f *testing.F) {
f.Add("48000/a")
f.Fuzz(func(_ *testing.T, a string) {
Unmarshal("audio", 96, "Opus/"+a, nil) //nolint:errcheck
})
}
func FuzzUnmarshalOpusMulti(f *testing.F) {
f.Add("48000/a")
f.Fuzz(func(_ *testing.T, a string) {
Unmarshal("audio", 96, "multiopus/"+a, nil) //nolint:errcheck
})
}
func FuzzUnmarshalVorbis(f *testing.F) {
f.Fuzz(func(_ *testing.T, a, b string) {
Unmarshal("audio", 96, "Vorbis/"+a, map[string]string{ //nolint:errcheck
"configuration": b,
})
})
}
func FuzzUnmarshalVP8(f *testing.F) {
f.Fuzz(func(_ *testing.T, a, b string) {
Unmarshal("video", 96, "VP8/90000", map[string]string{ //nolint:errcheck
"max-fr": a,
"max-fs": b,
})
})
}
func FuzzUnmarshalVP9(f *testing.F) {
f.Fuzz(func(_ *testing.T, a, b, c string) {
Unmarshal("video", 96, "VP9/90000", map[string]string{ //nolint:errcheck
"max-fr": a,
"max-fs": b,
"profile-id": c,
})
})
} }

View File

@@ -61,3 +61,25 @@ func TestH264DecEncoder(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, [][]byte{{0x01, 0x02, 0x03, 0x04}}, byts) require.Equal(t, [][]byte{{0x01, 0x02, 0x03, 0x04}}, byts)
} }
func FuzzUnmarshalH264(f *testing.F) {
f.Fuzz(func(
_ *testing.T,
a bool,
b string,
c bool,
d string,
) {
ma := map[string]string{}
if a {
ma["sprop-parameter-sets"] = b
}
if c {
ma["packetization-mode"] = d
}
Unmarshal("video", 96, "H264/90000", ma) //nolint:errcheck
})
}

View File

@@ -70,3 +70,33 @@ func TestH265DecEncoder(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, [][]byte{{0x01, 0x02, 0x03, 0x04}}, byts) require.Equal(t, [][]byte{{0x01, 0x02, 0x03, 0x04}}, byts)
} }
func FuzzUnmarshalH265(f *testing.F) {
f.Fuzz(func(
_ *testing.T,
a bool,
b string,
c bool,
d string,
) {
ma := map[string]string{}
if a {
ma["sprop-vps"] = b
}
if c {
ma["sprop-sps"] = d
}
if c {
ma["sprop-pps"] = d
}
if c {
ma["sprop-max-don-diff"] = d
}
Unmarshal("video", 96, "H265/90000", ma) //nolint:errcheck
})
}

View File

@@ -41,3 +41,9 @@ func TestLPCMDecEncoder(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, byts) require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, byts)
} }
func FuzzUnmarshalLPCM(f *testing.F) {
f.Fuzz(func(_ *testing.T, a string) {
Unmarshal("audio", 96, "L16/"+a, nil) //nolint:errcheck
})
}

View File

@@ -124,3 +124,107 @@ func TestMPEG4AudioDecEncoder(t *testing.T) {
require.Equal(t, [][]byte{{0x01, 0x02, 0x03, 0x04}}, byts) require.Equal(t, [][]byte{{0x01, 0x02, 0x03, 0x04}}, byts)
}) })
} }
func FuzzUnmarshalMPEG4AudioGeneric(f *testing.F) {
f.Fuzz(func(
_ *testing.T,
a bool,
b string,
c bool,
d string,
e bool,
f string,
g bool,
h string,
i bool,
j string,
k bool,
l string,
m bool,
n string,
) {
ma := map[string]string{}
if a {
ma["streamtype"] = b
}
if c {
ma["mode"] = d
}
if e {
ma["profile-level-id"] = f
}
if g {
ma["config"] = h
}
if i {
ma["sizelength"] = j
}
if k {
ma["indexlength"] = l
}
if m {
ma["indexdeltalength"] = n
}
fo, err := Unmarshal("audio", 96, "MPEG4-generic/48000/2", ma) //nolint:errcheck
if err == nil {
fo.(*MPEG4Audio).GetConfig()
}
})
}
func FuzzUnmarshalMPEG4AudioLATM(f *testing.F) {
f.Fuzz(func(
_ *testing.T,
a bool,
b string,
c bool,
d string,
e bool,
f string,
g bool,
h string,
i bool,
j string,
k bool,
l string,
) {
ma := map[string]string{}
if a {
ma["profile-level-id"] = b
}
if c {
ma["bitrate"] = d
}
if e {
ma["cpresent"] = f
}
if g {
ma["config"] = h
}
if i {
ma["object"] = j
}
if k {
ma["sbr-enabled"] = l
}
fo, err := Unmarshal("audio", 96, "MP4A-LATM/48000/2", ma) //nolint:errcheck
if err == nil {
fo.(*MPEG4Audio).GetConfig()
}
})
}

View File

@@ -37,3 +37,25 @@ func TestMPEG4VideoDecEncoder(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, byts) require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, byts)
} }
func FuzzUnmarshalMPEG4Video(f *testing.F) {
f.Fuzz(func(
_ *testing.T,
a bool,
b string,
c bool,
d string,
) {
ma := map[string]string{}
if a {
ma["profile-level-id"] = b
}
if c {
ma["config"] = d
}
Unmarshal("audio", 96, "MP4V-ES/90000", ma) //nolint:errcheck
})
}

View File

@@ -34,3 +34,19 @@ func TestOpusDecEncoder(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, byts) require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, byts)
} }
func FuzzUnmarshalOpus(f *testing.F) {
f.Add("48000/a")
f.Fuzz(func(_ *testing.T, a string) {
Unmarshal("audio", 96, "Opus/"+a, nil) //nolint:errcheck
})
}
func FuzzUnmarshalOpusMulti(f *testing.F) {
f.Add("48000/a")
f.Fuzz(func(_ *testing.T, a string) {
Unmarshal("audio", 96, "multiopus/"+a, nil) //nolint:errcheck
})
}

View File

@@ -0,0 +1,7 @@
go test fuzz v1
bool(true)
string("")
bool(false)
string(" \x17T\x9b")
bool(true)
string("")

View File

@@ -0,0 +1,7 @@
go test fuzz v1
bool(true)
string("")
bool(true)
string("")
bool(false)
string("7XXB")

View File

@@ -0,0 +1,7 @@
go test fuzz v1
bool(true)
string("")
bool(false)
string("")
bool(false)
string("")

View File

@@ -1,4 +1,5 @@
go test fuzz v1 go test fuzz v1
bool(false)
string("") string("")
bool(true)
string("") string("")
string("0")

View File

@@ -0,0 +1,5 @@
go test fuzz v1
bool(true)
string("1,")
bool(true)
string("")

View File

@@ -1,3 +0,0 @@
go test fuzz v1
string("0,")
string("0")

View File

@@ -1,3 +1,5 @@
go test fuzz v1 go test fuzz v1
bool(true)
string(",0") string(",0")
bool(true)
string("0") string("0")

View File

@@ -1,3 +0,0 @@
go test fuzz v1
string(",")
string("0")

View File

@@ -0,0 +1,5 @@
go test fuzz v1
bool(false)
string("6")
bool(true)
string("\v\xd7F?O\xc1\x86\t")

View File

@@ -0,0 +1,5 @@
go test fuzz v1
bool(false)
string("\xd9\xf3fdž\xd7\xf6\x1d6")
bool(true)
string("\v\xd7F?O\xc1\x86\t")

View File

@@ -1,5 +0,0 @@
go test fuzz v1
string("0")
string("0")
string("")
string("0")

View File

@@ -1,5 +1,5 @@
go test fuzz v1 go test fuzz v1
bool(false)
string("") string("")
string("") bool(true)
string("0")
string("") string("")

View File

@@ -1,3 +1,5 @@
go test fuzz v1 go test fuzz v1
bool(true)
string("0") string("0")
bool(false)
string("") string("")

View File

@@ -1,5 +0,0 @@
go test fuzz v1
string("0")
string("\x00")
string("")
string("0\xa5")

View File

@@ -1,5 +0,0 @@
go test fuzz v1
string("0")
string("A")
string("\xb3\xbd\xcf\xf4\x10\xa6")
string("")

View File

@@ -0,0 +1,5 @@
go test fuzz v1
bool(false)
string("6")
bool(true)
string("")

View File

@@ -0,0 +1,15 @@
go test fuzz v1
bool(true)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")

View File

@@ -0,0 +1,15 @@
go test fuzz v1
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(true)
string("")
bool(true)
string("")
bool(false)
string("")

View File

@@ -0,0 +1,15 @@
go test fuzz v1
bool(true)
string("wB\xaa(A\x0e}")
bool(true)
string("\xe4o\xe0^\xae\t")
bool(true)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("D")
bool(true)
string("")

View File

@@ -0,0 +1,15 @@
go test fuzz v1
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(true)
string("")
bool(false)
string("")

View File

@@ -0,0 +1,15 @@
go test fuzz v1
bool(true)
string("")
bool(false)
string("")
bool(true)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")

View File

@@ -0,0 +1,15 @@
go test fuzz v1
bool(false)
string("")
bool(false)
string("")
bool(true)
string("")
bool(true)
string("u7\xae")
bool(true)
string("")
bool(true)
string("")
bool(false)
string("")

View File

@@ -0,0 +1,15 @@
go test fuzz v1
bool(true)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(true)
string("")

View File

@@ -0,0 +1,15 @@
go test fuzz v1
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")

View File

@@ -0,0 +1,15 @@
go test fuzz v1
bool(true)
string("")
bool(false)
string("")
bool(false)
string("")
bool(true)
string("")
bool(true)
string("")
bool(false)
string("")
bool(true)
string("")

View File

@@ -0,0 +1,15 @@
go test fuzz v1
bool(false)
string("0")
bool(false)
string("")
bool(false)
string("0")
bool(true)
string("1010")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")

View File

@@ -0,0 +1,13 @@
go test fuzz v1
bool(false)
string("")
bool(true)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")

View File

@@ -0,0 +1,13 @@
go test fuzz v1
bool(false)
string("")
bool(false)
string("")
bool(true)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("0")

View File

@@ -0,0 +1,13 @@
go test fuzz v1
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("")

View File

@@ -0,0 +1,13 @@
go test fuzz v1
bool(false)
string("")
bool(false)
string("")
bool(true)
string("")
bool(true)
string("")
bool(false)
string("")
bool(true)
string("0")

View File

@@ -0,0 +1,13 @@
go test fuzz v1
bool(true)
string("")
bool(false)
string("")
bool(true)
string("")
bool(false)
string("")
bool(false)
string("")
bool(false)
string("0")

View File

@@ -0,0 +1,13 @@
go test fuzz v1
bool(false)
string("0")
bool(false)
string("")
bool(true)
string("")
bool(true)
string("0")
bool(false)
string("0")
bool(true)
string("0")

View File

@@ -0,0 +1,13 @@
go test fuzz v1
bool(false)
string("")
bool(true)
string("0")
bool(false)
string("0")
bool(true)
string("70002010")
bool(true)
string("0")
bool(true)
string("0")

View File

@@ -1,4 +1,5 @@
go test fuzz v1 go test fuzz v1
bool(true)
string("") string("")
bool(true)
string("") string("")
string("1")

View File

@@ -0,0 +1,5 @@
go test fuzz v1
bool(false)
string("")
bool(true)
string("")

View File

@@ -1,3 +1,5 @@
go test fuzz v1 go test fuzz v1
string("0") bool(false)
string("") string("")
bool(true)
string("0")

View File

@@ -1,3 +0,0 @@
go test fuzz v1
string("0")
string("0")

View File

@@ -1,3 +0,0 @@
go test fuzz v1
string("A")
string("")

View File

@@ -1,5 +1,5 @@
go test fuzz v1 go test fuzz v1
string("") bool(true)
string("")
string("")
string("A") string("A")
bool(false)
string("")

View File

@@ -1,3 +0,0 @@
go test fuzz v1
string("A")
string("")

View File

@@ -1,3 +1,5 @@
go test fuzz v1 go test fuzz v1
bool(false)
string("0") string("0")
bool(true)
string("") string("")

View File

@@ -0,0 +1,7 @@
go test fuzz v1
bool(false)
string("")
bool(true)
string("")
bool(true)
string("")

View File

@@ -1,4 +0,0 @@
go test fuzz v1
string("1")
string("")
string("#")

View File

@@ -0,0 +1,7 @@
go test fuzz v1
bool(false)
string("")
bool(false)
string("")
bool(true)
string("")

View File

@@ -0,0 +1,7 @@
go test fuzz v1
bool(true)
string("")
bool(false)
string("")
bool(true)
string("")

View File

@@ -18,3 +18,11 @@ func TestVorbisAttributes(t *testing.T) {
require.Equal(t, 48000, format.ClockRate()) require.Equal(t, 48000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }
func FuzzUnmarshalVorbis(f *testing.F) {
f.Fuzz(func(_ *testing.T, a, b string) {
Unmarshal("audio", 96, "Vorbis/"+a, map[string]string{ //nolint:errcheck
"configuration": b,
})
})
}

View File

@@ -33,3 +33,25 @@ func TestVP8DecEncoder(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, byts) require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, byts)
} }
func FuzzUnmarshalVP8(f *testing.F) {
f.Fuzz(func(
_ *testing.T,
a bool,
b string,
c bool,
d string,
) {
ma := map[string]string{}
if a {
ma["max-fr"] = b
}
if c {
ma["max-fs"] = d
}
Unmarshal("audio", 96, "VP8/90000", ma) //nolint:errcheck
})
}

View File

@@ -33,3 +33,31 @@ func TestVP9DecEncoder(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, []byte{0x82, 0x49, 0x83, 0x42, 0x0, 0x77, 0xf0, 0x32, 0x34}, byts) require.Equal(t, []byte{0x82, 0x49, 0x83, 0x42, 0x0, 0x77, 0xf0, 0x32, 0x34}, byts)
} }
func FuzzUnmarshalVP9(f *testing.F) {
f.Fuzz(func(
_ *testing.T,
a bool,
b string,
c bool,
d string,
e bool,
f string,
) {
ma := map[string]string{}
if a {
ma["max-fr"] = b
}
if c {
ma["max-fs"] = d
}
if e {
ma["profile-id"] = f
}
Unmarshal("audio", 96, "VP9/90000", ma) //nolint:errcheck
})
}