improve fuzz tests (#592)

This commit is contained in:
Alessandro Ros
2024-08-01 16:33:04 +02:00
committed by GitHub
parent e2d1e6dab4
commit 92cf812d01
30 changed files with 144 additions and 41 deletions

2
go.mod
View File

@@ -3,7 +3,7 @@ module github.com/bluenviron/gortsplib/v4
go 1.20
require (
github.com/bluenviron/mediacommon v1.12.1
github.com/bluenviron/mediacommon v1.12.2-0.20240801134301-b013c7a52029
github.com/google/uuid v1.6.0
github.com/pion/rtcp v1.2.14
github.com/pion/rtp v1.8.7-0.20240429002300-bc5124c9d0d0

4
go.sum
View File

@@ -2,8 +2,8 @@ github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflx
github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
github.com/asticode/go-astits v1.13.0 h1:XOgkaadfZODnyZRR5Y0/DWkA9vrkLLPLeeOvDwfKZ1c=
github.com/asticode/go-astits v1.13.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI=
github.com/bluenviron/mediacommon v1.12.1 h1:sgDJaKV6OXrPCSO0KPp9zi/pwNWtKHenn5/dvjtY+Tg=
github.com/bluenviron/mediacommon v1.12.1/go.mod h1:HDyW2CzjvhYJXtdxstdFPio3G0qSocPhqkhUt/qffec=
github.com/bluenviron/mediacommon v1.12.2-0.20240801134301-b013c7a52029 h1:s9PNLf98P0uRiBqvY6qKrO1pssPZVCVhs17aSNfXuLY=
github.com/bluenviron/mediacommon v1.12.2-0.20240801134301-b013c7a52029/go.mod h1:HDyW2CzjvhYJXtdxstdFPio3G0qSocPhqkhUt/qffec=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View File

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

View File

@@ -49,10 +49,13 @@ func FuzzBodyUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, a string, b []byte) {
var p body
p.unmarshal( //nolint:errcheck
err := p.unmarshal(
Header{
"Content-Length": HeaderValue{a},
},
bufio.NewReader(bytes.NewReader(b)))
if err == nil {
p.marshal()
}
})
}

View File

@@ -138,6 +138,9 @@ func FuzzHeaderUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b []byte) {
var h Header
h.unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck
err := h.unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
if err == nil {
h.marshal()
}
})
}

View File

@@ -60,6 +60,9 @@ func FuzzInterleavedFrameUnmarshal(f *testing.F) {
}
f.Fuzz(func(_ *testing.T, b []byte) {
var f InterleavedFrame
f.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck
err := f.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
if err == nil {
f.Marshal() //nolint:errcheck
}
})
}

View File

@@ -188,6 +188,9 @@ func FuzzRequestUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b []byte) {
var req Request
req.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck
err := req.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
if err == nil {
req.Marshal() //nolint:errcheck
}
})
}

View File

@@ -162,6 +162,9 @@ func FuzzResponseUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b []byte) {
var res Response
res.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck
err := res.Unmarshal(bufio.NewReader(bytes.NewBuffer(b)))
if err == nil {
res.Marshal() //nolint:errcheck
}
})
}

View File

@@ -837,7 +837,7 @@ func TestSessionFindFormat(t *testing.T) {
require.Equal(t, tr, forma)
}
func FuzzSessionUnmarshalErrors(f *testing.F) {
func FuzzSessionUnmarshal(f *testing.F) {
for _, ca := range casesSession {
f.Add(ca.in)
}
@@ -898,11 +898,9 @@ func FuzzSessionUnmarshalErrors(f *testing.F) {
f.Fuzz(func(_ *testing.T, enc string) {
var sd sdp.SessionDescription
err := sd.Unmarshal([]byte(enc))
if err != nil {
return
}
if err == nil {
var desc Session
desc.Unmarshal(&sd) //nolint:errcheck
}
})
}

View File

@@ -58,6 +58,10 @@ func FuzzUnmarshalAV1(f *testing.F) {
ma["tier"] = f
}
Unmarshal("video", 96, "AV1/90000", ma) //nolint:errcheck
fo, err := Unmarshal("video", 96, "AV1/90000", ma)
if err == nil {
fo.(*AV1).RTPMap()
fo.(*AV1).FMTP()
}
})
}

View File

@@ -80,6 +80,10 @@ func FuzzUnmarshalH264(f *testing.F) {
ma["packetization-mode"] = d
}
Unmarshal("video", 96, "H264/90000", ma) //nolint:errcheck
fo, err := Unmarshal("video", 96, "H264/90000", ma)
if err == nil {
fo.RTPMap()
fo.FMTP()
}
})
}

View File

@@ -97,6 +97,10 @@ func FuzzUnmarshalH265(f *testing.F) {
ma["sprop-max-don-diff"] = d
}
Unmarshal("video", 96, "H265/90000", ma) //nolint:errcheck
fo, err := Unmarshal("video", 96, "H265/90000", ma)
if err == nil {
fo.RTPMap()
fo.FMTP()
}
})
}

View File

@@ -44,6 +44,10 @@ func TestLPCMDecEncoder(t *testing.T) {
func FuzzUnmarshalLPCM(f *testing.F) {
f.Fuzz(func(_ *testing.T, a string) {
Unmarshal("audio", 96, "L16/"+a, nil) //nolint:errcheck
fo, err := Unmarshal("audio", 96, "L16/"+a, nil)
if err == nil {
fo.RTPMap()
fo.FMTP()
}
})
}

View File

@@ -174,6 +174,9 @@ func (f *MPEG4Audio) ClockRate() int {
if !f.LATM {
return f.Config.SampleRate
}
if f.CPresent {
return 16000
}
return f.StreamMuxConfig.Programs[0].Layers[0].AudioSpecificConfig.SampleRate
}
@@ -199,6 +202,10 @@ func (f *MPEG4Audio) RTPMap() string {
"/" + strconv.FormatInt(int64(channelCount), 10)
}
if f.CPresent {
return "MP4A-LATM/16000/1"
}
aoc := f.StreamMuxConfig.Programs[0].Layers[0].AudioSpecificConfig
sampleRate := aoc.SampleRate
@@ -251,15 +258,8 @@ func (f *MPEG4Audio) FMTP() map[string]string {
return fmtp
}
enc, err := f.StreamMuxConfig.Marshal()
if err != nil {
return nil
}
fmtp := map[string]string{
"profile-level-id": strconv.FormatInt(int64(f.ProfileLevelID), 10),
"config": hex.EncodeToString(enc),
"object": strconv.FormatInt(int64(f.StreamMuxConfig.Programs[0].Layers[0].AudioSpecificConfig.Type), 10),
}
if f.Bitrate != nil {
@@ -270,6 +270,14 @@ func (f *MPEG4Audio) FMTP() map[string]string {
fmtp["cpresent"] = "1"
} else {
fmtp["cpresent"] = "0"
enc, err := f.StreamMuxConfig.Marshal()
if err != nil {
return nil
}
fmtp["config"] = hex.EncodeToString(enc)
fmtp["object"] = strconv.FormatInt(int64(f.StreamMuxConfig.Programs[0].Layers[0].AudioSpecificConfig.Type), 10)
}
if f.SBREnabled != nil {

View File

@@ -222,8 +222,10 @@ func FuzzUnmarshalMPEG4AudioLATM(f *testing.F) {
ma["sbr-enabled"] = l
}
fo, err := Unmarshal("audio", 96, "MP4A-LATM/48000/2", ma) //nolint:errcheck
fo, err := Unmarshal("audio", 96, "MP4A-LATM/48000/2", ma)
if err == nil {
fo.(*MPEG4Audio).RTPMap()
fo.(*MPEG4Audio).FMTP()
fo.(*MPEG4Audio).GetConfig()
}
})

View File

@@ -56,6 +56,10 @@ func FuzzUnmarshalMPEG4Video(f *testing.F) {
ma["config"] = d
}
Unmarshal("audio", 96, "MP4V-ES/90000", ma) //nolint:errcheck
fo, err := Unmarshal("audio", 96, "MP4V-ES/90000", ma)
if err == nil {
fo.RTPMap()
fo.FMTP()
}
})
}

View File

@@ -39,7 +39,11 @@ func FuzzUnmarshalOpus(f *testing.F) {
f.Add("48000/a")
f.Fuzz(func(_ *testing.T, a string) {
Unmarshal("audio", 96, "Opus/"+a, nil) //nolint:errcheck
fo, err := Unmarshal("audio", 96, "Opus/"+a, nil)
if err == nil {
fo.RTPMap()
fo.FMTP()
}
})
}
@@ -47,6 +51,10 @@ func FuzzUnmarshalOpusMulti(f *testing.F) {
f.Add("48000/a")
f.Fuzz(func(_ *testing.T, a string) {
Unmarshal("audio", 96, "multiopus/"+a, nil) //nolint:errcheck
fo, err := Unmarshal("audio", 96, "multiopus/"+a, nil)
if err == nil {
fo.RTPMap()
fo.FMTP()
}
})
}

View File

@@ -0,0 +1,13 @@
go test fuzz v1
bool(false)
string("0")
bool(true)
string("0")
bool(true)
string("0")
bool(true)
string("70102010")
bool(true)
string("0")
bool(true)
string("0")

View File

@@ -21,8 +21,12 @@ func TestVorbisAttributes(t *testing.T) {
func FuzzUnmarshalVorbis(f *testing.F) {
f.Fuzz(func(_ *testing.T, a, b string) {
Unmarshal("audio", 96, "Vorbis/"+a, map[string]string{ //nolint:errcheck
fo, err := Unmarshal("audio", 96, "Vorbis/"+a, map[string]string{
"configuration": b,
})
if err == nil {
fo.RTPMap()
fo.FMTP()
}
})
}

View File

@@ -52,6 +52,10 @@ func FuzzUnmarshalVP8(f *testing.F) {
ma["max-fs"] = d
}
Unmarshal("audio", 96, "VP8/90000", ma) //nolint:errcheck
fo, err := Unmarshal("audio", 96, "VP8/90000", ma)
if err == nil {
fo.RTPMap()
fo.FMTP()
}
})
}

View File

@@ -58,6 +58,10 @@ func FuzzUnmarshalVP9(f *testing.F) {
ma["profile-id"] = f
}
Unmarshal("audio", 96, "VP9/90000", ma) //nolint:errcheck
fo, err := Unmarshal("audio", 96, "VP9/90000", ma)
if err == nil {
fo.RTPMap()
fo.FMTP()
}
})
}

View File

@@ -134,7 +134,10 @@ func FuzzAuthenticateUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h Authenticate
h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
}
})
}

View File

@@ -130,7 +130,10 @@ func FuzzAuthorizationUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h Authorization
h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
}
})
}

View File

@@ -151,7 +151,10 @@ func FuzzRangeUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h Range
h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
}
})
}

View File

@@ -158,7 +158,10 @@ func FuzzRTPInfoUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h RTPInfo
h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
}
})
}

View File

@@ -71,7 +71,10 @@ func FuzzSessionUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h Session
h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
}
})
}

View File

@@ -256,7 +256,10 @@ func FuzzTransportsUnmarshal(f *testing.F) {
f.Fuzz(func(_ *testing.T, b string) {
var h Transports
h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck
err := h.Unmarshal(base.HeaderValue{b})
if err == nil {
h.Marshal()
}
})
}

View File

@@ -3070,7 +3070,10 @@ func FuzzUnmarshal(f *testing.F) {
}
f.Fuzz(func(_ *testing.T, b string) {
desc := SessionDescription{}
desc.Unmarshal([]byte(b)) //nolint:errcheck
var desc SessionDescription
err := desc.Unmarshal([]byte(b))
if err == nil {
desc.Marshal() //nolint:errcheck
}
})
}