ensure unmarshaled entities can be marshaled back (#773)

This commit is contained in:
Alessandro Ros
2025-05-04 11:27:28 +02:00
committed by GitHub
parent 3e555e2d18
commit 7f5aac27d1
22 changed files with 89 additions and 50 deletions

View File

@@ -105,11 +105,13 @@ func FuzzSender(f *testing.F) {
f.Fuzz(func(_ *testing.T, a string) {
se, err := NewSender(base.HeaderValue{a}, "myuser", "mypass")
if err == nil {
if err != nil {
return
}
se.AddAuthorization(&base.Request{
Method: base.Setup,
URL: mustParseURL("rtsp://myhost/mypath?key=val/trackID=3"),
})
}
})
}

View File

@@ -54,8 +54,10 @@ func FuzzBodyUnmarshal(f *testing.F) {
"Content-Length": HeaderValue{a},
},
bufio.NewReader(bytes.NewReader(b)))
if err == nil {
p.marshal()
if err != nil {
return
}
p.marshal()
})
}

View File

@@ -139,8 +139,10 @@ func FuzzHeaderUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b []byte) {
var h Header
err := h.unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
if err == nil {
h.marshal()
if err != nil {
return
}
h.marshal()
})
}

View File

@@ -58,11 +58,14 @@ func FuzzInterleavedFrameUnmarshal(f *testing.F) {
for _, ca := range casesInterleavedFrame {
f.Add(ca.enc)
}
f.Fuzz(func(_ *testing.T, b []byte) {
f.Fuzz(func(t *testing.T, b []byte) {
var f InterleavedFrame
err := f.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
if err == nil {
f.Marshal() //nolint:errcheck
if err != nil {
return
}
_, err = f.Marshal()
require.NoError(t, err)
})
}

View File

@@ -186,11 +186,14 @@ func FuzzRequestUnmarshal(f *testing.F) {
f.Add(ca.byts)
}
f.Fuzz(func(_ *testing.T, b []byte) {
f.Fuzz(func(t *testing.T, b []byte) {
var req Request
err := req.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
if err == nil {
req.Marshal() //nolint:errcheck
if err != nil {
return
}
_, err = req.Marshal()
require.NoError(t, err)
})
}

View File

@@ -160,11 +160,14 @@ func FuzzResponseUnmarshal(f *testing.F) {
f.Add(ca.byts)
}
f.Fuzz(func(_ *testing.T, b []byte) {
f.Fuzz(func(t *testing.T, b []byte) {
var res Response
err := res.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
if err == nil {
res.Marshal() //nolint:errcheck
if err != nil {
return
}
_, err = res.Marshal()
require.NoError(t, err)
})
}

View File

@@ -783,6 +783,7 @@ func FuzzSessionUnmarshal(f *testing.F) {
require.NotZero(t, len(desc.Medias))
desc.Marshal(false) //nolint:errcheck
_, err = desc.Marshal(false)
require.NoError(t, err)
})
}

View File

@@ -31,12 +31,13 @@ func TestDecode(t *testing.T) {
}
func FuzzDecoder(f *testing.F) {
f.Fuzz(func(_ *testing.T, b []byte) {
f.Fuzz(func(t *testing.T, b []byte) {
d := &Decoder{
BitDepth: 24,
ChannelCount: 2,
}
d.Init() //nolint:errcheck
err := d.Init()
require.NoError(t, err)
d.Decode(&rtp.Packet{ //nolint:errcheck
Header: rtp.Header{

View File

@@ -131,9 +131,10 @@ func TestDecodeFixedQuantizationTable(t *testing.T) {
}
func FuzzDecoder(f *testing.F) {
f.Fuzz(func(_ *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{}
d.Init() //nolint:errcheck
err := d.Init()
require.NoError(t, err)
d.Decode(&rtp.Packet{ //nolint:errcheck
Header: rtp.Header{

View File

@@ -27,9 +27,10 @@ func TestDecode(t *testing.T) {
}
func FuzzDecoder(f *testing.F) {
f.Fuzz(func(_ *testing.T, a []byte, b []byte) {
f.Fuzz(func(t *testing.T, a []byte, b []byte) {
d := &Decoder{}
d.Init() //nolint:errcheck
err := d.Init()
require.NoError(t, err)
d.Decode(&rtp.Packet{ //nolint:errcheck
Header: rtp.Header{

View File

@@ -57,9 +57,10 @@ func TestDecodeErrorMissingPacket(t *testing.T) {
}
func FuzzDecoder(f *testing.F) {
f.Fuzz(func(_ *testing.T, a []byte, b []byte) {
f.Fuzz(func(t *testing.T, a []byte, b []byte) {
d := &Decoder{}
d.Init() //nolint:errcheck
err := d.Init()
require.NoError(t, err)
d.Decode(&rtp.Packet{ //nolint:errcheck
Header: rtp.Header{

View File

@@ -104,11 +104,12 @@ func TestDecodeLATMErrorMissingPacket(t *testing.T) {
}
func FuzzDecoderLATM(f *testing.F) {
f.Fuzz(func(_ *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{
LATM: true,
}
d.Init() //nolint:errcheck
err := d.Init()
require.NoError(t, err)
d.Decode(&rtp.Packet{ //nolint:errcheck
Header: rtp.Header{

View File

@@ -62,9 +62,10 @@ func TestDecodeErrorMissingPacket(t *testing.T) {
}
func FuzzDecoder(f *testing.F) {
f.Fuzz(func(_ *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{}
d.Init() //nolint:errcheck
err := d.Init()
require.NoError(t, err)
d.Decode(&rtp.Packet{ //nolint:errcheck
Header: rtp.Header{

View File

@@ -58,9 +58,10 @@ func TestDecodeErrorMissingPacket(t *testing.T) {
}
func FuzzDecoder(f *testing.F) {
f.Fuzz(func(_ *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{}
d.Init() //nolint:errcheck
err := d.Init()
require.NoError(t, err)
d.Decode(&rtp.Packet{ //nolint:errcheck
Header: rtp.Header{

View File

@@ -66,9 +66,10 @@ func TestDecodeErrorMissingPacket(t *testing.T) {
}
func FuzzDecoder(f *testing.F) {
f.Fuzz(func(_ *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{}
d.Init() //nolint:errcheck
err := d.Init()
require.NoError(t, err)
d.Decode(&rtp.Packet{ //nolint:errcheck
Header: rtp.Header{

View File

@@ -135,9 +135,11 @@ func FuzzAuthenticateUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h Authenticate
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
if err != nil {
return
}
h.Marshal()
})
}

View File

@@ -132,9 +132,11 @@ func FuzzAuthorizationUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h Authorization
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
if err != nil {
return
}
h.Marshal()
})
}

View File

@@ -152,9 +152,11 @@ func FuzzRangeUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h Range
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
if err != nil {
return
}
h.Marshal()
})
}

View File

@@ -159,9 +159,11 @@ func FuzzRTPInfoUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h RTPInfo
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
if err != nil {
return
}
h.Marshal()
})
}

View File

@@ -72,9 +72,11 @@ func FuzzSessionUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h Session
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
if err != nil {
return
}
h.Marshal()
})
}

View File

@@ -257,9 +257,11 @@ func FuzzTransportsUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h Transports
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
if err != nil {
return
}
h.Marshal()
})
}

View File

@@ -3226,11 +3226,14 @@ func FuzzUnmarshal(f *testing.F) {
f.Add(string(c.enc))
}
f.Fuzz(func(_ *testing.T, b string) {
f.Fuzz(func(t *testing.T, b string) {
var desc SessionDescription
err := desc.Unmarshal([]byte(b))
if err == nil {
desc.Marshal() //nolint:errcheck
if err != nil {
return
}
_, err = desc.Marshal()
require.NoError(t, err)
})
}