Skip to content

Commit b13e9c4

Browse files
authored
tests/fuzzers: fix false positive in bitutil fuzzer (#22076)
1 parent 9c6b5b9 commit b13e9c4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tests/fuzzers/bitutil/compress_fuzz.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,19 @@ func fuzzDecode(data []byte) int {
5151
if err != nil {
5252
return 0
5353
}
54-
if comp := bitutil.CompressBytes(blob); !bytes.Equal(comp, data) {
54+
// re-compress it (it's OK if the re-compressed differs from the
55+
// original - the first input may not have been compressed at all)
56+
comp := bitutil.CompressBytes(blob)
57+
if len(comp) > len(blob) {
58+
// After compression, it must be smaller or equal
59+
panic("bad compression")
60+
}
61+
// But decompressing it once again should work
62+
decomp, err := bitutil.DecompressBytes(data, 1024)
63+
if err != nil {
64+
panic(err)
65+
}
66+
if !bytes.Equal(decomp, blob) {
5567
panic("content mismatch")
5668
}
5769
return 1

0 commit comments

Comments
 (0)