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 #591

Merged
merged 1 commit into from
Aug 1, 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
28 changes: 28 additions & 0 deletions pkg/format/av1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,31 @@ func TestAV1DecEncoder(t *testing.T) {
require.NoError(t, err)
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
})
}
183 changes: 0 additions & 183 deletions pkg/format/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1123,187 +1123,4 @@ func TestUnmarshalErrors(t *testing.T) {
_, err := Unmarshal("video", 96, "", map[string]string{})
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,
})
})
}
22 changes: 22 additions & 0 deletions pkg/format/h264_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,25 @@ func TestH264DecEncoder(t *testing.T) {
require.NoError(t, err)
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
})
}
30 changes: 30 additions & 0 deletions pkg/format/h265_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,33 @@ func TestH265DecEncoder(t *testing.T) {
require.NoError(t, err)
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
})
}
6 changes: 6 additions & 0 deletions pkg/format/lpcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ func TestLPCMDecEncoder(t *testing.T) {
require.NoError(t, err)
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
})
}
104 changes: 104 additions & 0 deletions pkg/format/mpeg4_audio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,107 @@ func TestMPEG4AudioDecEncoder(t *testing.T) {
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()
}
})
}
Loading
Loading