mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
ensure unmarshaled entities can be marshaled back (#773)
This commit is contained in:
@@ -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"),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@@ -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()
|
||||
})
|
||||
}
|
||||
|
@@ -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()
|
||||
})
|
||||
}
|
||||
|
@@ -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)
|
||||
})
|
||||
}
|
||||
|
@@ -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)
|
||||
})
|
||||
}
|
||||
|
@@ -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)
|
||||
})
|
||||
}
|
||||
|
@@ -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)
|
||||
})
|
||||
}
|
||||
|
@@ -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{
|
||||
|
@@ -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{
|
||||
|
@@ -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{
|
||||
|
@@ -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{
|
||||
|
@@ -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{
|
||||
|
@@ -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{
|
||||
|
@@ -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{
|
||||
|
@@ -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{
|
||||
|
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user