jpeg: add fuzz tests

This commit is contained in:
aler9
2023-01-08 12:01:04 +01:00
parent 8a1dd54d61
commit c9d7b05308
15 changed files with 48 additions and 4 deletions

View File

@@ -19,10 +19,6 @@ type DefineQuantizationTable struct {
// Unmarshal decodes the marker.
func (m *DefineQuantizationTable) Unmarshal(buf []byte) error {
for len(buf) != 0 {
if len(buf) < 1 {
return fmt.Errorf("image is too short")
}
id := buf[0] & 0x0F
precision := buf[0] >> 4
buf = buf[1:]

View File

@@ -67,3 +67,10 @@ func TestDefineQuantizationTableMarshal(t *testing.T) {
})
}
}
func FuzzDefineQuantizationTableUnmarshal(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
var h DefineQuantizationTable
h.Unmarshal(b)
})
}

View File

@@ -32,3 +32,10 @@ func TestDefineRestartIntervalUnmarshal(t *testing.T) {
})
}
}
func FuzzDefineRestartIntervalUnmarshal(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
var h DefineRestartInterval
h.Unmarshal(b)
})
}

View File

@@ -47,3 +47,10 @@ func TestStartOfFrame1Marshal(t *testing.T) {
})
}
}
func FuzzStartOfFrame1Unmarshal(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
var h StartOfFrame1
h.Unmarshal(b)
})
}

View File

@@ -40,3 +40,10 @@ func TestStartOfScanMarshal(t *testing.T) {
})
}
}
func FuzzStartOfScanUnmarshal(f *testing.F) {
f.Fuzz(func(t *testing.T, b []byte) {
var h StartOfScan
h.Unmarshal(b)
})
}

View File

@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("\b0000\x030!00\x110000")

View File

@@ -0,0 +1,2 @@
go test fuzz v1
[]byte("\b0000\x030!0000000")

View File

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

View File

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

View File

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

View File

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