formatprocessor: add fuzz tests (#2612)

This commit is contained in:
Alessandro Ros 2023-10-30 19:52:45 +01:00 committed by GitHub
parent 7fb3b749d5
commit a2c092ea44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 32 additions and 4 deletions

View file

@ -13,7 +13,7 @@ import (
)
// extract SPS and PPS without decoding RTP packets
func rtpH264ExtractSPSPPS(payload []byte) ([]byte, []byte) {
func rtpH264ExtractParams(payload []byte) ([]byte, []byte) {
if len(payload) < 1 {
return nil, nil
}
@ -112,7 +112,7 @@ func (t *formatProcessorH264) createEncoder(
}
func (t *formatProcessorH264) updateTrackParametersFromRTPPacket(payload []byte) {
sps, pps := rtpH264ExtractSPSPPS(payload)
sps, pps := rtpH264ExtractParams(payload)
if (sps != nil && !bytes.Equal(sps, t.format.SPS)) ||
(pps != nil && !bytes.Equal(pps, t.format.PPS)) {

View file

@ -200,3 +200,9 @@ func TestH264EmptyPacket(t *testing.T) {
// if all NALUs have been removed, no RTP packets must be generated.
require.Equal(t, []*rtp.Packet(nil), unit.RTPPackets)
}
func FuzzRTPH264ExtractParams(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
rtpH264ExtractParams(b)
})
}

View file

@ -13,7 +13,7 @@ import (
)
// extract VPS, SPS and PPS without decoding RTP packets
func rtpH265ExtractVPSSPSPPS(payload []byte) ([]byte, []byte, []byte) {
func rtpH265ExtractParams(payload []byte) ([]byte, []byte, []byte) {
if len(payload) < 2 {
return nil, nil, nil
}
@ -119,7 +119,7 @@ func (t *formatProcessorH265) createEncoder(
}
func (t *formatProcessorH265) updateTrackParametersFromRTPPacket(payload []byte) {
vps, sps, pps := rtpH265ExtractVPSSPSPPS(payload)
vps, sps, pps := rtpH265ExtractParams(payload)
if (vps != nil && !bytes.Equal(vps, t.format.VPS)) ||
(sps != nil && !bytes.Equal(sps, t.format.SPS)) ||

View file

@ -196,3 +196,9 @@ func TestH265EmptyPacket(t *testing.T) {
// if all NALUs have been removed, no RTP packets must be generated.
require.Equal(t, []*rtp.Packet(nil), unit.RTPPackets)
}
func FuzzRTPH265ExtractParams(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
rtpH265ExtractParams(b)
})
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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