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 #139

Merged
merged 1 commit into from
Aug 1, 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
5 changes: 4 additions & 1 deletion pkg/codecs/ac3/bsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func FuzzBSIUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var bsi BSI
bsi.Unmarshal(b) //nolint:errcheck
err := bsi.Unmarshal(b)
if err == nil {
bsi.ChannelCount() //nolint:staticcheck
}
})
}
6 changes: 5 additions & 1 deletion pkg/codecs/ac3/sync_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ func FuzzSyncInfoUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var syncInfo SyncInfo
syncInfo.Unmarshal(b) //nolint:errcheck
err := syncInfo.Unmarshal(b)
if err == nil {
syncInfo.FrameSize()
syncInfo.SampleRate() //nolint:staticcheck
}
})
}
5 changes: 4 additions & 1 deletion pkg/codecs/av1/bitstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func FuzzBitstreamUnmarshal(f *testing.F) {
}

f.Fuzz(func(_ *testing.T, b []byte) {
BitstreamUnmarshal(b, true) //nolint:errcheck
tu, err := BitstreamUnmarshal(b, true)
if err == nil {
BitstreamMarshal(tu) //nolint:errcheck
}
})
}
6 changes: 5 additions & 1 deletion pkg/codecs/av1/leb128_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func FuzzLEB128Unmarshal(f *testing.F) {
}

f.Fuzz(func(_ *testing.T, b []byte) {
LEB128Unmarshal(b) //nolint:errcheck
v, _, err := LEB128Unmarshal(b)
if err == nil {
enc := make([]byte, LEB128MarshalSize(v))
LEB128MarshalTo(v, enc)
}
})
}
6 changes: 5 additions & 1 deletion pkg/codecs/av1/sequence_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ func FuzzSequenceHeaderUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var sh SequenceHeader
sh.Unmarshal(b) //nolint:errcheck
err := sh.Unmarshal(b)
if err == nil {
sh.Width()
sh.Height()
}
})
}
5 changes: 4 additions & 1 deletion pkg/codecs/h264/annexb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func FuzzAnnexBUnmarshal(f *testing.F) {
}

f.Fuzz(func(_ *testing.T, b []byte) {
AnnexBUnmarshal(b) //nolint:errcheck
au, err := AnnexBUnmarshal(b)
if err == nil {
AnnexBMarshal(au) //nolint:errcheck
}
})
}
5 changes: 4 additions & 1 deletion pkg/codecs/h264/avcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func FuzzAVCCUnmarshal(f *testing.F) {
}

f.Fuzz(func(_ *testing.T, b []byte) {
AVCCUnmarshal(b) //nolint:errcheck
au, err := AVCCUnmarshal(b)
if err == nil {
AVCCMarshal(au) //nolint:errcheck
}
})
}
7 changes: 6 additions & 1 deletion pkg/codecs/h264/sps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ func FuzzSPSUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var sps SPS
sps.Unmarshal(b) //nolint:errcheck
err := sps.Unmarshal(b) //nolint:errcheck
if err == nil {
sps.Width()
sps.Height()
sps.FPS()
}
})
}
7 changes: 6 additions & 1 deletion pkg/codecs/h265/sps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ func FuzzSPSUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var sps SPS
sps.Unmarshal(b) //nolint:errcheck
err := sps.Unmarshal(b)
if err == nil {
sps.Width()
sps.Height()
sps.FPS()
}
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("B000000000000000\xff\xffX000$8")
6 changes: 5 additions & 1 deletion pkg/codecs/mpeg1audio/frame_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func FuzzFrameHeaderUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var h FrameHeader
h.Unmarshal(b) //nolint:errcheck
err := h.Unmarshal(b)
if err == nil {
h.FrameLen() //nolint:staticcheck
h.SampleCount() //nolint:staticcheck
}
})
}
4 changes: 2 additions & 2 deletions pkg/codecs/mpeg4audio/adts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
)

// ADTSPacket is an ADTS frame.
// ADTSPacket is an ADTS packet.
// Specification: ISO 14496-3, Table 1.A.5
type ADTSPacket struct {
Type ObjectType
Expand All @@ -13,7 +13,7 @@ type ADTSPacket struct {
AU []byte
}

// ADTSPackets is a group od ADTS packets.
// ADTSPackets is a group of ADTS packets.
type ADTSPackets []*ADTSPacket

// Unmarshal decodes an ADTS stream into ADTS packets.
Expand Down
5 changes: 4 additions & 1 deletion pkg/codecs/mpeg4audio/adts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func FuzzADTSUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var pkts ADTSPackets
pkts.Unmarshal(b) //nolint:errcheck
err := pkts.Unmarshal(b)
if err == nil {
pkts.Marshal() //nolint:errcheck
}
})
}
5 changes: 4 additions & 1 deletion pkg/codecs/mpeg4audio/audio_specific_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ func FuzzAudioSpecificConfigUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var conf AudioSpecificConfig
conf.Unmarshal(b) //nolint:errcheck
err := conf.Unmarshal(b)
if err == nil {
conf.Marshal() //nolint:errcheck
}
})
}
5 changes: 4 additions & 1 deletion pkg/codecs/mpeg4audio/stream_mux_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ func FuzzStreamMuxConfigUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var conf StreamMuxConfig
conf.Unmarshal(b) //nolint:errcheck
err := conf.Unmarshal(b)
if err == nil {
conf.Marshal() //nolint:errcheck
}
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("A0 70005")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("A0 0\xa5")
6 changes: 5 additions & 1 deletion pkg/formats/fmp4/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,11 @@ func FuzzInitUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var init Init
init.Unmarshal(bytes.NewReader(b)) //nolint:errcheck
err := init.Unmarshal(bytes.NewReader(b))
if err == nil {
var buf seekablebuffer.Buffer
init.Marshal(&buf) //nolint:errcheck
}
})
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/formats/fmp4/parts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ func FuzzPartsUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var parts Parts
parts.Unmarshal(b) //nolint:errcheck
err := parts.Unmarshal(b)
if err == nil {
var buf seekablebuffer.Buffer
parts.Marshal(&buf) //nolint:errcheck
}
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("\x00\x00\x00`moof\x00\x00\x00\x10mfhd\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00Htraf\x00\x00\x00\x10tfhd\x00\x02\x00\x00\x00\x00\x00d\x00\x00\x00\x14tfdt\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01_\x90\x00\x00\x00\x1ctrun\x00\x00\x00\n\\dat\x01h")
6 changes: 5 additions & 1 deletion pkg/formats/mpegts/opus_access_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func FuzzOpusAccessUnitUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var h opusAccessUnit
h.unmarshal(b) //nolint:errcheck
_, err := h.unmarshal(b) //nolint:errcheck
if err == nil {
buf := make([]byte, h.marshalSize())
h.marshalTo(buf) //nolint:errcheck
}
})
}
6 changes: 5 additions & 1 deletion pkg/formats/mpegts/opus_control_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func FuzzOpusControlHeaderUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, b []byte) {
var h opusControlHeader
h.unmarshal(b) //nolint:errcheck
_, err := h.unmarshal(b)
if err == nil {
buf := make([]byte, h.marshalSize())
h.marshalTo(buf) //nolint:errcheck
}
})
}
Loading