Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve fuzz tests #127

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/codecs/ac3/bsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func TestBSIUnmarshal(t *testing.T) {
}

func FuzzBSIUnmarshal(f *testing.F) {
for _, ca := range ac3Cases {
f.Add(ca.enc[5:])
}

f.Fuzz(func(_ *testing.T, b []byte) {
var bsi BSI
bsi.Unmarshal(b) //nolint:errcheck
Expand Down
4 changes: 4 additions & 0 deletions pkg/codecs/ac3/sync_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ func TestSyncInfoUnmarshal(t *testing.T) {
}

func FuzzSyncInfoUnmarshal(f *testing.F) {
for _, ca := range ac3Cases {
f.Add(ca.enc)
}

f.Fuzz(func(_ *testing.T, b []byte) {
var syncInfo SyncInfo
syncInfo.Unmarshal(b) //nolint:errcheck
Expand Down
4 changes: 4 additions & 0 deletions pkg/codecs/av1/bitstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func TestBitstreamMarshal(t *testing.T) {
}

func FuzzBitstreamUnmarshal(f *testing.F) {
for _, ca := range casesBitstream {
f.Add(ca.enc)
}

f.Fuzz(func(_ *testing.T, b []byte) {
BitstreamUnmarshal(b, true) //nolint:errcheck
})
Expand Down
4 changes: 4 additions & 0 deletions pkg/codecs/av1/leb128_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func TestLEB128Marshal(t *testing.T) {
}

func FuzzLEB128Unmarshal(f *testing.F) {
for _, ca := range casesLEB128 {
f.Add(ca.enc)
}

f.Fuzz(func(_ *testing.T, b []byte) {
LEB128Unmarshal(b) //nolint:errcheck
})
Expand Down
40 changes: 23 additions & 17 deletions pkg/codecs/av1/obu_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ import (
"github.com/stretchr/testify/require"
)

func TestOBUHeaderUnmarshal(t *testing.T) {
for _, ca := range []struct {
name string
byts []byte
h OBUHeader
}{
{
"sequence header",
[]byte{
0x0a, 0x0e, 0x00, 0x00, 0x00, 0x4a, 0xab, 0xbf,
0xc3, 0x77, 0x6b, 0xe4, 0x40, 0x40, 0x40, 0x41,
},
OBUHeader{
Type: OBUTypeSequenceHeader,
HasSize: true,
},
var casesOBUHeader = []struct {
name string
byts []byte
h OBUHeader
}{
{
"sequence header",
[]byte{
0x0a, 0x0e, 0x00, 0x00, 0x00, 0x4a, 0xab, 0xbf,
0xc3, 0x77, 0x6b, 0xe4, 0x40, 0x40, 0x40, 0x41,
},
OBUHeader{
Type: OBUTypeSequenceHeader,
HasSize: true,
},
} {
},
}

func TestOBUHeaderUnmarshal(t *testing.T) {
for _, ca := range casesOBUHeader {
t.Run(ca.name, func(t *testing.T) {
var h OBUHeader
err := h.Unmarshal(ca.byts)
Expand All @@ -34,6 +36,10 @@ func TestOBUHeaderUnmarshal(t *testing.T) {
}

func FuzzOBUHeaderUnmarshal(f *testing.F) {
for _, ca := range casesOBUHeader {
f.Add(ca.byts)
}

f.Fuzz(func(_ *testing.T, b []byte) {
var h OBUHeader
h.Unmarshal(b) //nolint:errcheck
Expand Down
232 changes: 119 additions & 113 deletions pkg/codecs/av1/sequence_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,125 +6,127 @@ import (
"github.com/stretchr/testify/require"
)

func TestSequenceHeaderUnmarshal(t *testing.T) {
for _, ca := range []struct {
name string
byts []byte
sh SequenceHeader
width int
height int
}{
{
"chrome webrtc",
[]byte{
8, 0, 0, 0, 66, 167, 191, 228, 96, 13, 0, 64,
},
SequenceHeader{
OperatingPointIdc: []uint16{0},
SeqLevelIdx: []uint8{8},
SeqTier: []bool{false},
DecoderModelPresentForThisOp: []bool{false},
InitialDisplayPresentForThisOp: []bool{false},
InitialDisplayDelayMinus1: []uint8{0},
MaxFrameWidthMinus1: 1919,
MaxFrameHeightMinus1: 803,
SeqChooseScreenContentTools: true,
SeqForceScreenContentTools: 2,
SeqChooseIntegerMv: true,
SeqForceIntegerMv: 2,
EnableCdef: true,
ColorConfig: SequenceHeader_ColorConfig{
BitDepth: 8,
ColorPrimaries: 2,
TransferCharacteristics: 2,
MatrixCoefficients: 2,
SubsamplingX: true,
SubsamplingY: true,
},
},
1920,
804,
var casesSequenceHeader = []struct {
name string
byts []byte
sh SequenceHeader
width int
height int
}{
{
"chrome webrtc",
[]byte{
8, 0, 0, 0, 66, 167, 191, 228, 96, 13, 0, 64,
},
{
"av1 sample",
[]byte{
10, 11, 0, 0, 0, 66, 167, 191, 230, 46, 223, 200, 66,
SequenceHeader{
OperatingPointIdc: []uint16{0},
SeqLevelIdx: []uint8{8},
SeqTier: []bool{false},
DecoderModelPresentForThisOp: []bool{false},
InitialDisplayPresentForThisOp: []bool{false},
InitialDisplayDelayMinus1: []uint8{0},
MaxFrameWidthMinus1: 1919,
MaxFrameHeightMinus1: 803,
SeqChooseScreenContentTools: true,
SeqForceScreenContentTools: 2,
SeqChooseIntegerMv: true,
SeqForceIntegerMv: 2,
EnableCdef: true,
ColorConfig: SequenceHeader_ColorConfig{
BitDepth: 8,
ColorPrimaries: 2,
TransferCharacteristics: 2,
MatrixCoefficients: 2,
SubsamplingX: true,
SubsamplingY: true,
},
SequenceHeader{
OperatingPointIdc: []uint16{0},
SeqLevelIdx: []uint8{8},
SeqTier: []bool{false},
DecoderModelPresentForThisOp: []bool{false},
InitialDisplayPresentForThisOp: []bool{false},
InitialDisplayDelayMinus1: []uint8{0},
MaxFrameWidthMinus1: 1919,
MaxFrameHeightMinus1: 817,
Use128x128Superblock: true,
EnableFilterIntra: true,
EnableIntraEdgeFilter: true,
EnableMaskedCompound: true,
EnableWarpedMotion: true,
EnableOrderHint: true,
EnableJntComp: true,
EnableRefFrameMvs: true,
SeqChooseScreenContentTools: true,
SeqForceScreenContentTools: 2,
SeqChooseIntegerMv: true,
OrderHintBitsMinus1: 6,
SeqForceIntegerMv: 2,
EnableCdef: true,
ColorConfig: SequenceHeader_ColorConfig{
BitDepth: 8,
ColorPrimaries: 2,
TransferCharacteristics: 2,
MatrixCoefficients: 2,
ColorRange: true,
SubsamplingX: true,
SubsamplingY: true,
},
},
1920,
818,
},
{
"libsvtav1",
[]byte{
0x8, 0x0, 0x0, 0x0, 0x42, 0xab, 0xbf, 0xc3, 0x71, 0xab, 0xe6, 0x1,
1920,
804,
},
{
"av1 sample",
[]byte{
10, 11, 0, 0, 0, 66, 167, 191, 230, 46, 223, 200, 66,
},
SequenceHeader{
OperatingPointIdc: []uint16{0},
SeqLevelIdx: []uint8{8},
SeqTier: []bool{false},
DecoderModelPresentForThisOp: []bool{false},
InitialDisplayPresentForThisOp: []bool{false},
InitialDisplayDelayMinus1: []uint8{0},
MaxFrameWidthMinus1: 1919,
MaxFrameHeightMinus1: 817,
Use128x128Superblock: true,
EnableFilterIntra: true,
EnableIntraEdgeFilter: true,
EnableMaskedCompound: true,
EnableWarpedMotion: true,
EnableOrderHint: true,
EnableJntComp: true,
EnableRefFrameMvs: true,
SeqChooseScreenContentTools: true,
SeqForceScreenContentTools: 2,
SeqChooseIntegerMv: true,
OrderHintBitsMinus1: 6,
SeqForceIntegerMv: 2,
EnableCdef: true,
ColorConfig: SequenceHeader_ColorConfig{
BitDepth: 8,
ColorPrimaries: 2,
TransferCharacteristics: 2,
MatrixCoefficients: 2,
ColorRange: true,
SubsamplingX: true,
SubsamplingY: true,
},
SequenceHeader{
OperatingPointIdc: []uint16{0},
SeqLevelIdx: []uint8{8},
SeqTier: []bool{false},
DecoderModelPresentForThisOp: []bool{false},
InitialDisplayPresentForThisOp: []bool{false},
InitialDisplayDelayMinus1: []uint8{0},
MaxFrameWidthMinus1: 1919,
MaxFrameHeightMinus1: 1079,
EnableIntraEdgeFilter: true,
EnableInterintraCompound: true,
EnableWarpedMotion: true,
EnableOrderHint: true,
EnableRefFrameMvs: true,
SeqChooseScreenContentTools: true,
SeqForceScreenContentTools: 2,
SeqChooseIntegerMv: true,
SeqForceIntegerMv: 2,
OrderHintBitsMinus1: 6,
EnableCdef: true,
EnableRestoration: true,
ColorConfig: SequenceHeader_ColorConfig{
BitDepth: 8,
ColorPrimaries: 2,
TransferCharacteristics: 2,
MatrixCoefficients: 2,
SubsamplingX: true,
SubsamplingY: true,
},
},
1920,
818,
},
{
"libsvtav1",
[]byte{
0x8, 0x0, 0x0, 0x0, 0x42, 0xab, 0xbf, 0xc3, 0x71, 0xab, 0xe6, 0x1,
},
SequenceHeader{
OperatingPointIdc: []uint16{0},
SeqLevelIdx: []uint8{8},
SeqTier: []bool{false},
DecoderModelPresentForThisOp: []bool{false},
InitialDisplayPresentForThisOp: []bool{false},
InitialDisplayDelayMinus1: []uint8{0},
MaxFrameWidthMinus1: 1919,
MaxFrameHeightMinus1: 1079,
EnableIntraEdgeFilter: true,
EnableInterintraCompound: true,
EnableWarpedMotion: true,
EnableOrderHint: true,
EnableRefFrameMvs: true,
SeqChooseScreenContentTools: true,
SeqForceScreenContentTools: 2,
SeqChooseIntegerMv: true,
SeqForceIntegerMv: 2,
OrderHintBitsMinus1: 6,
EnableCdef: true,
EnableRestoration: true,
ColorConfig: SequenceHeader_ColorConfig{
BitDepth: 8,
ColorPrimaries: 2,
TransferCharacteristics: 2,
MatrixCoefficients: 2,
SubsamplingX: true,
SubsamplingY: true,
},
1920,
1080,
},
} {
1920,
1080,
},
}

func TestSequenceHeaderUnmarshal(t *testing.T) {
for _, ca := range casesSequenceHeader {
t.Run(ca.name, func(t *testing.T) {
var sh SequenceHeader
err := sh.Unmarshal(ca.byts)
Expand All @@ -137,6 +139,10 @@ func TestSequenceHeaderUnmarshal(t *testing.T) {
}

func FuzzSequenceHeaderUnmarshal(f *testing.F) {
for _, ca := range casesSequenceHeader {
f.Add(ca.byts)
}

f.Fuzz(func(_ *testing.T, b []byte) {
var sh SequenceHeader
sh.Unmarshal(b) //nolint:errcheck
Expand Down
4 changes: 4 additions & 0 deletions pkg/codecs/h264/annexb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func BenchmarkAnnexBUnmarshal(b *testing.B) {
}

func FuzzAnnexBUnmarshal(f *testing.F) {
for _, ca := range casesAnnexB {
f.Add(ca.encin)
}

f.Fuzz(func(_ *testing.T, b []byte) {
AnnexBUnmarshal(b) //nolint:errcheck
})
Expand Down
4 changes: 4 additions & 0 deletions pkg/codecs/h264/avcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func TestAVCCMarshal(t *testing.T) {
}

func FuzzAVCCUnmarshal(f *testing.F) {
for _, ca := range casesAVCC {
f.Add(ca.enc)
}

f.Fuzz(func(_ *testing.T, b []byte) {
AVCCUnmarshal(b) //nolint:errcheck
})
Expand Down
Loading
Loading