rewrite fuzz tests of decoders in order to get deterministic results (#261)

This commit is contained in:
Alessandro Ros
2023-04-26 12:30:51 +02:00
committed by GitHub
parent d6a55f882a
commit d56ae1f600
63 changed files with 192 additions and 99 deletions

View File

@@ -184,10 +184,22 @@ func TestDecodeUntilMarker(t *testing.T) {
} }
func FuzzDecoder(f *testing.F) { func FuzzDecoder(f *testing.F) {
d := &Decoder{} f.Fuzz(func(t *testing.T, a []byte, b []byte) {
d.Init() d := &Decoder{}
d.Init()
d.Decode(&rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: a,
})
f.Fuzz(func(t *testing.T, b []byte) {
d.Decode(&rtp.Packet{ d.Decode(&rtp.Packet{
Header: rtp.Header{ Header: rtp.Header{
Version: 2, Version: 2,

View File

@@ -1,2 +0,0 @@
go test fuzz v1
[]byte("\x1c\xd4")

View File

@@ -1,3 +1,3 @@
go test fuzz v1 go test fuzz v1
[]byte("0") []byte("0")
bool(false) []byte("")

View File

@@ -1,3 +1,3 @@
go test fuzz v1 go test fuzz v1
[]byte("0") []byte("0")
bool(false) []byte("<")

View File

@@ -0,0 +1,3 @@
go test fuzz v1
[]byte("0")
[]byte("\\0")

View File

@@ -36,10 +36,22 @@ func TestDecode(t *testing.T) {
} }
func FuzzDecoder(f *testing.F) { func FuzzDecoder(f *testing.F) {
d := &Decoder{} f.Fuzz(func(t *testing.T, a []byte, b []byte) {
d.Init() d := &Decoder{}
d.Init()
d.Decode(&rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: false,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: a,
})
f.Fuzz(func(t *testing.T, b []byte) {
d.Decode(&rtp.Packet{ d.Decode(&rtp.Packet{
Header: rtp.Header{ Header: rtp.Header{
Version: 2, Version: 2,

View File

@@ -1,3 +1,3 @@
go test fuzz v1 go test fuzz v1
[]byte("00") []byte("00")
bool(false) []byte("b00")

View File

@@ -0,0 +1,3 @@
go test fuzz v1
[]byte("0")
[]byte("\xe50")

View File

@@ -0,0 +1,3 @@
go test fuzz v1
[]byte("b0\xd2")
[]byte("0")

View File

@@ -1,2 +0,0 @@
go test fuzz v1
[]byte("bbbbbbbbbbbbb0")

View File

@@ -31,14 +31,14 @@ func TestDecode(t *testing.T) {
} }
func FuzzDecoder(f *testing.F) { func FuzzDecoder(f *testing.F) {
d := &Decoder{
BitDepth: 24,
SampleRate: 48000,
ChannelCount: 2,
}
d.Init()
f.Fuzz(func(t *testing.T, b []byte) { f.Fuzz(func(t *testing.T, b []byte) {
d := &Decoder{
BitDepth: 24,
SampleRate: 48000,
ChannelCount: 2,
}
d.Init()
d.Decode(&rtp.Packet{ d.Decode(&rtp.Packet{
Header: rtp.Header{ Header: rtp.Header{
Version: 2, Version: 2,

View File

@@ -28,14 +28,26 @@ func TestDecode(t *testing.T) {
} }
func FuzzDecoder(f *testing.F) { func FuzzDecoder(f *testing.F) {
d := &Decoder{} f.Fuzz(func(t *testing.T, a []byte, am bool, b []byte, bm bool) {
d.Init() d := &Decoder{}
d.Init()
f.Fuzz(func(t *testing.T, b []byte, m bool) {
d.Decode(&rtp.Packet{ d.Decode(&rtp.Packet{
Header: rtp.Header{ Header: rtp.Header{
Version: 2, Version: 2,
Marker: m, Marker: am,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: a,
})
d.Decode(&rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: bm,
PayloadType: 96, PayloadType: 96,
SequenceNumber: 17645, SequenceNumber: 17645,
Timestamp: 2289527317, Timestamp: 2289527317,

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("0\x00\x00\x00\x01\xff000\x00\x00@000000000000000000000000000000000000000000000000000000000000000000")
bool(true)
[]byte("0000\x01\xff000000000000000000000000000000000000000000000000000000000000000000000000")
bool(true)

View File

@@ -1,3 +0,0 @@
go test fuzz v1
[]byte("0\x00\x00\x00\x01\xff000\x00\x00@0000000000000000000000000000000000000000000000000000000000000000")
bool(true)

View File

@@ -1,3 +1,5 @@
go test fuzz v1 go test fuzz v1
[]byte("0")
bool(false)
[]byte("0\x00\x00\x00\x01\xff00") []byte("0\x00\x00\x00\x01\xff00")
bool(false) bool(false)

View File

@@ -1,5 +1,5 @@
go test fuzz v1 go test fuzz v1
[]byte("") []byte("")
bool(false)
[]byte("")
bool(true) bool(true)
[]byte("")
bool(false)

View File

@@ -1,3 +0,0 @@
go test fuzz v1
[]byte("0000\x01\xff00000000000000000000000000000000000000000000000000000000000000000000000")
bool(true)

View File

@@ -1,3 +0,0 @@
go test fuzz v1
[]byte("0000\x01\xff00")
bool(false)

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("0\x00\x00\x00\x01\xff000\x00\x00\x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
bool(false)
[]byte("0000\x01\xff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
bool(false)

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("0")
bool(true)
[]byte("0\x00\x00\x00\x01\xff000\x00\x00\x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
bool(true)

View File

@@ -1,3 +0,0 @@
go test fuzz v1
[]byte("0000\x01\xff00000000000000000000000000000000000000000000000000000000000000000000000")
bool(false)

View File

@@ -27,10 +27,10 @@ func TestDecode(t *testing.T) {
} }
func FuzzDecoder(f *testing.F) { func FuzzDecoder(f *testing.F) {
d := &Decoder{}
d.Init()
f.Fuzz(func(t *testing.T, a []byte, b []byte) { f.Fuzz(func(t *testing.T, a []byte, b []byte) {
d := &Decoder{}
d.Init()
d.Decode(&rtp.Packet{ d.Decode(&rtp.Packet{
Header: rtp.Header{ Header: rtp.Header{
Version: 2, Version: 2,

View File

@@ -1,3 +1,3 @@
go test fuzz v1 go test fuzz v1
[]byte("\x00\x00\x00\x000")
[]byte("0") []byte("0")
[]byte("\x00\x00\x00\x000")

View File

@@ -0,0 +1,3 @@
go test fuzz v1
[]byte("\x00\x00\x00\x00\xff\xfd000")
[]byte("\x00\x00000")

View File

@@ -1,3 +0,0 @@
go test fuzz v1
[]byte("\x00\x00\x00\x05\xff\xff\x05000000000000000000000000000000000000000\xcf\x1c\xe9b\x01NUI00000000000000000000000000000000000000000000000000000000")
[]byte("\x00\x00\x00\x05\xff\xff\x0500")

View File

@@ -1,3 +1,3 @@
go test fuzz v1 go test fuzz v1
[]byte("0") []byte("0")
[]byte("\x00\x00\x00\x00\xff\xfa\x160000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\xff\xfa000") []byte("\x00\x00\x00\x00\xff\xfb\x15000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\xff\xfb000")

View File

@@ -1,3 +1,3 @@
go test fuzz v1 go test fuzz v1
[]byte("") []byte("0")
[]byte("00000") []byte("00000")

View File

@@ -70,15 +70,15 @@ func TestDecodeADTS(t *testing.T) {
} }
func FuzzDecoder(f *testing.F) { func FuzzDecoder(f *testing.F) {
d := &Decoder{
SampleRate: 16000,
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}
d.Init()
f.Fuzz(func(t *testing.T, a []byte, am bool, b []byte, bm bool) { f.Fuzz(func(t *testing.T, a []byte, am bool, b []byte, bm bool) {
d := &Decoder{
SampleRate: 16000,
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}
d.Init()
d.Decode(&rtp.Packet{ d.Decode(&rtp.Packet{
Header: rtp.Header{ Header: rtp.Header{
Version: 2, Version: 2,

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("0")
bool(true)
[]byte("\x00\x1000")
bool(true)

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("")
bool(false)
[]byte("")
bool(false)

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("\x00\x01\x00\x00")
bool(false)
[]byte("\x00\x0100")
bool(false)

View File

@@ -1,5 +0,0 @@
go test fuzz v1
[]byte("\x000\x00\x00\xd8\xd8\xd8\xc8\xd8\xd801")
bool(true)
[]byte("\x00\x01\x00\x00")
bool(true)

View File

@@ -1,5 +0,0 @@
go test fuzz v1
[]byte("\x00000000000")
bool(false)
[]byte("")
bool(true)

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("\x00\x01\x00\x00")
bool(false)
[]byte("\x00 0000")
bool(true)

View File

@@ -2,4 +2,4 @@ go test fuzz v1
[]byte("00") []byte("00")
bool(false) bool(false)
[]byte("") []byte("")
bool(true) bool(false)

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("\x00 0000")
bool(false)
[]byte("0")
bool(true)

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("0")
bool(false)
[]byte("\x00\x0100")
bool(false)

View File

@@ -1,5 +0,0 @@
go test fuzz v1
[]byte("\x00\x10\x00\x00")
bool(false)
[]byte("\x00\x1000")
bool(false)

View File

@@ -1,5 +1,5 @@
go test fuzz v1 go test fuzz v1
[]byte("\x00\x00")
bool(false)
[]byte("") []byte("")
bool(false)
[]byte("\x00\x00")
bool(true) bool(true)

View File

@@ -27,14 +27,26 @@ func TestDecode(t *testing.T) {
} }
func FuzzDecoder(f *testing.F) { func FuzzDecoder(f *testing.F) {
d := &Decoder{} f.Fuzz(func(t *testing.T, a []byte, am bool, b []byte, bm bool) {
d.Init() d := &Decoder{}
d.Init()
f.Fuzz(func(t *testing.T, b []byte, m bool) {
d.Decode(&rtp.Packet{ d.Decode(&rtp.Packet{
Header: rtp.Header{ Header: rtp.Header{
Version: 2, Version: 2,
Marker: m, Marker: am,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: a,
})
d.Decode(&rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: bm,
PayloadType: 96, PayloadType: 96,
SequenceNumber: 17645, SequenceNumber: 17645,
Timestamp: 2289527317, Timestamp: 2289527317,

View File

@@ -1,3 +1,5 @@
go test fuzz v1 go test fuzz v1
[]byte("")
bool(false)
[]byte("1000") []byte("1000")
bool(false) bool(false)

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("")
bool(false)
[]byte("")
bool(false)

View File

@@ -0,0 +1,5 @@
go test fuzz v1
[]byte("\xf8\x9a\x9f000")
bool(true)
[]byte(" 00000")
bool(false)

View File

@@ -1,3 +0,0 @@
go test fuzz v1
[]byte(" 000")
bool(false)

View File

@@ -27,14 +27,26 @@ func TestDecode(t *testing.T) {
} }
func FuzzDecoder(f *testing.F) { func FuzzDecoder(f *testing.F) {
d := &Decoder{} f.Fuzz(func(t *testing.T, a []byte, am bool, b []byte, bm bool) {
d.Init() d := &Decoder{}
d.Init()
f.Fuzz(func(t *testing.T, b []byte, m bool) {
d.Decode(&rtp.Packet{ d.Decode(&rtp.Packet{
Header: rtp.Header{ Header: rtp.Header{
Version: 2, Version: 2,
Marker: m, Marker: am,
PayloadType: 96,
SequenceNumber: 17645,
Timestamp: 2289527317,
SSRC: 0x9dbb7812,
},
Payload: a,
})
d.Decode(&rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: bm,
PayloadType: 96, PayloadType: 96,
SequenceNumber: 17645, SequenceNumber: 17645,
Timestamp: 2289527317, Timestamp: 2289527317,

View File

@@ -1,5 +1,5 @@
go test fuzz v1 go test fuzz v1
[]byte("00") []byte("M")
bool(false)
[]byte("\x00\f00")
bool(true) bool(true)
[]byte("A")
bool(false)

View File

@@ -1,5 +1,5 @@
go test fuzz v1 go test fuzz v1
[]byte("0") []byte("0")
bool(false) bool(false)
[]byte("\x00\f00") []byte("")
bool(false) bool(false)

View File

@@ -1,3 +0,0 @@
go test fuzz v1
[]byte("")
bool(true)