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) {
|
f.Fuzz(func(_ *testing.T, a string) {
|
||||||
se, err := NewSender(base.HeaderValue{a}, "myuser", "mypass")
|
se, err := NewSender(base.HeaderValue{a}, "myuser", "mypass")
|
||||||
if err == nil {
|
if err != nil {
|
||||||
se.AddAuthorization(&base.Request{
|
return
|
||||||
Method: base.Setup,
|
|
||||||
URL: mustParseURL("rtsp://myhost/mypath?key=val/trackID=3"),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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},
|
"Content-Length": HeaderValue{a},
|
||||||
},
|
},
|
||||||
bufio.NewReader(bytes.NewReader(b)))
|
bufio.NewReader(bytes.NewReader(b)))
|
||||||
if err == nil {
|
if err != nil {
|
||||||
p.marshal()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.marshal()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -139,8 +139,10 @@ func FuzzHeaderUnmarshal(f *testing.F) {
|
|||||||
f.Fuzz(func(_ *testing.T, b []byte) {
|
f.Fuzz(func(_ *testing.T, b []byte) {
|
||||||
var h Header
|
var h Header
|
||||||
err := h.unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
|
err := h.unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
|
||||||
if err == nil {
|
if err != nil {
|
||||||
h.marshal()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.marshal()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -58,11 +58,14 @@ func FuzzInterleavedFrameUnmarshal(f *testing.F) {
|
|||||||
for _, ca := range casesInterleavedFrame {
|
for _, ca := range casesInterleavedFrame {
|
||||||
f.Add(ca.enc)
|
f.Add(ca.enc)
|
||||||
}
|
}
|
||||||
f.Fuzz(func(_ *testing.T, b []byte) {
|
f.Fuzz(func(t *testing.T, b []byte) {
|
||||||
var f InterleavedFrame
|
var f InterleavedFrame
|
||||||
err := f.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
|
err := f.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
|
||||||
if err == nil {
|
if err != nil {
|
||||||
f.Marshal() //nolint:errcheck
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = f.Marshal()
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -186,11 +186,14 @@ func FuzzRequestUnmarshal(f *testing.F) {
|
|||||||
f.Add(ca.byts)
|
f.Add(ca.byts)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.Fuzz(func(_ *testing.T, b []byte) {
|
f.Fuzz(func(t *testing.T, b []byte) {
|
||||||
var req Request
|
var req Request
|
||||||
err := req.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
|
err := req.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
|
||||||
if err == nil {
|
if err != nil {
|
||||||
req.Marshal() //nolint:errcheck
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = req.Marshal()
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -160,11 +160,14 @@ func FuzzResponseUnmarshal(f *testing.F) {
|
|||||||
f.Add(ca.byts)
|
f.Add(ca.byts)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.Fuzz(func(_ *testing.T, b []byte) {
|
f.Fuzz(func(t *testing.T, b []byte) {
|
||||||
var res Response
|
var res Response
|
||||||
err := res.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
|
err := res.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
|
||||||
if err == nil {
|
if err != nil {
|
||||||
res.Marshal() //nolint:errcheck
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = res.Marshal()
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -783,6 +783,7 @@ func FuzzSessionUnmarshal(f *testing.F) {
|
|||||||
|
|
||||||
require.NotZero(t, len(desc.Medias))
|
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) {
|
func FuzzDecoder(f *testing.F) {
|
||||||
f.Fuzz(func(_ *testing.T, b []byte) {
|
f.Fuzz(func(t *testing.T, b []byte) {
|
||||||
d := &Decoder{
|
d := &Decoder{
|
||||||
BitDepth: 24,
|
BitDepth: 24,
|
||||||
ChannelCount: 2,
|
ChannelCount: 2,
|
||||||
}
|
}
|
||||||
d.Init() //nolint:errcheck
|
err := d.Init()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
d.Decode(&rtp.Packet{ //nolint:errcheck
|
d.Decode(&rtp.Packet{ //nolint:errcheck
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
|
@@ -131,9 +131,10 @@ func TestDecodeFixedQuantizationTable(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FuzzDecoder(f *testing.F) {
|
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 := &Decoder{}
|
||||||
d.Init() //nolint:errcheck
|
err := d.Init()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
d.Decode(&rtp.Packet{ //nolint:errcheck
|
d.Decode(&rtp.Packet{ //nolint:errcheck
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
|
@@ -27,9 +27,10 @@ func TestDecode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FuzzDecoder(f *testing.F) {
|
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 := &Decoder{}
|
||||||
d.Init() //nolint:errcheck
|
err := d.Init()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
d.Decode(&rtp.Packet{ //nolint:errcheck
|
d.Decode(&rtp.Packet{ //nolint:errcheck
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
|
@@ -57,9 +57,10 @@ func TestDecodeErrorMissingPacket(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FuzzDecoder(f *testing.F) {
|
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 := &Decoder{}
|
||||||
d.Init() //nolint:errcheck
|
err := d.Init()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
d.Decode(&rtp.Packet{ //nolint:errcheck
|
d.Decode(&rtp.Packet{ //nolint:errcheck
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
|
@@ -104,11 +104,12 @@ func TestDecodeLATMErrorMissingPacket(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FuzzDecoderLATM(f *testing.F) {
|
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{
|
d := &Decoder{
|
||||||
LATM: true,
|
LATM: true,
|
||||||
}
|
}
|
||||||
d.Init() //nolint:errcheck
|
err := d.Init()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
d.Decode(&rtp.Packet{ //nolint:errcheck
|
d.Decode(&rtp.Packet{ //nolint:errcheck
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
|
@@ -62,9 +62,10 @@ func TestDecodeErrorMissingPacket(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FuzzDecoder(f *testing.F) {
|
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 := &Decoder{}
|
||||||
d.Init() //nolint:errcheck
|
err := d.Init()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
d.Decode(&rtp.Packet{ //nolint:errcheck
|
d.Decode(&rtp.Packet{ //nolint:errcheck
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
|
@@ -58,9 +58,10 @@ func TestDecodeErrorMissingPacket(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FuzzDecoder(f *testing.F) {
|
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 := &Decoder{}
|
||||||
d.Init() //nolint:errcheck
|
err := d.Init()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
d.Decode(&rtp.Packet{ //nolint:errcheck
|
d.Decode(&rtp.Packet{ //nolint:errcheck
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
|
@@ -66,9 +66,10 @@ func TestDecodeErrorMissingPacket(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FuzzDecoder(f *testing.F) {
|
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 := &Decoder{}
|
||||||
d.Init() //nolint:errcheck
|
err := d.Init()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
d.Decode(&rtp.Packet{ //nolint:errcheck
|
d.Decode(&rtp.Packet{ //nolint:errcheck
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
|
@@ -135,9 +135,11 @@ func FuzzAuthenticateUnmarshal(f *testing.F) {
|
|||||||
f.Fuzz(func(_ *testing.T, b string) {
|
f.Fuzz(func(_ *testing.T, b string) {
|
||||||
var h Authenticate
|
var h Authenticate
|
||||||
err := h.Unmarshal(base.HeaderValue{b})
|
err := h.Unmarshal(base.HeaderValue{b})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
h.Marshal()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.Marshal()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -132,9 +132,11 @@ func FuzzAuthorizationUnmarshal(f *testing.F) {
|
|||||||
f.Fuzz(func(_ *testing.T, b string) {
|
f.Fuzz(func(_ *testing.T, b string) {
|
||||||
var h Authorization
|
var h Authorization
|
||||||
err := h.Unmarshal(base.HeaderValue{b})
|
err := h.Unmarshal(base.HeaderValue{b})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
h.Marshal()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.Marshal()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -152,9 +152,11 @@ func FuzzRangeUnmarshal(f *testing.F) {
|
|||||||
f.Fuzz(func(_ *testing.T, b string) {
|
f.Fuzz(func(_ *testing.T, b string) {
|
||||||
var h Range
|
var h Range
|
||||||
err := h.Unmarshal(base.HeaderValue{b})
|
err := h.Unmarshal(base.HeaderValue{b})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
h.Marshal()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.Marshal()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -159,9 +159,11 @@ func FuzzRTPInfoUnmarshal(f *testing.F) {
|
|||||||
f.Fuzz(func(_ *testing.T, b string) {
|
f.Fuzz(func(_ *testing.T, b string) {
|
||||||
var h RTPInfo
|
var h RTPInfo
|
||||||
err := h.Unmarshal(base.HeaderValue{b})
|
err := h.Unmarshal(base.HeaderValue{b})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
h.Marshal()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.Marshal()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -72,9 +72,11 @@ func FuzzSessionUnmarshal(f *testing.F) {
|
|||||||
f.Fuzz(func(_ *testing.T, b string) {
|
f.Fuzz(func(_ *testing.T, b string) {
|
||||||
var h Session
|
var h Session
|
||||||
err := h.Unmarshal(base.HeaderValue{b})
|
err := h.Unmarshal(base.HeaderValue{b})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
h.Marshal()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.Marshal()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -257,9 +257,11 @@ func FuzzTransportsUnmarshal(f *testing.F) {
|
|||||||
f.Fuzz(func(_ *testing.T, b string) {
|
f.Fuzz(func(_ *testing.T, b string) {
|
||||||
var h Transports
|
var h Transports
|
||||||
err := h.Unmarshal(base.HeaderValue{b})
|
err := h.Unmarshal(base.HeaderValue{b})
|
||||||
if err == nil {
|
if err != nil {
|
||||||
h.Marshal()
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.Marshal()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3226,11 +3226,14 @@ func FuzzUnmarshal(f *testing.F) {
|
|||||||
f.Add(string(c.enc))
|
f.Add(string(c.enc))
|
||||||
}
|
}
|
||||||
|
|
||||||
f.Fuzz(func(_ *testing.T, b string) {
|
f.Fuzz(func(t *testing.T, b string) {
|
||||||
var desc SessionDescription
|
var desc SessionDescription
|
||||||
err := desc.Unmarshal([]byte(b))
|
err := desc.Unmarshal([]byte(b))
|
||||||
if err == nil {
|
if err != nil {
|
||||||
desc.Marshal() //nolint:errcheck
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = desc.Marshal()
|
||||||
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user