Skip to content

Commit

Permalink
tests/fuzzers: fix false positive in bitutil fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Dec 26, 2020
1 parent b9012a0 commit ea5d2f5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/fuzzers/bitutil/compress_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@ func fuzzDecode(data []byte) int {
if err != nil {
return 0
}
if comp := bitutil.CompressBytes(blob); !bytes.Equal(comp, data) {
// re-compress it (it's OK if the re-compressed differs from the
// original - the first input may not have been compressed at all)
comp := bitutil.CompressBytes(blob)
if len(comp) > len(blob) {
// After compression, it must be smaller or equal
panic("bad compression")
}
// But decompressing it once again should work
decomp, err := bitutil.DecompressBytes(data, 1024)
if err != nil {
panic(err)
}
if !bytes.Equal(decomp, blob) {
panic("content mismatch")
}
return 1
Expand Down

0 comments on commit ea5d2f5

Please sign in to comment.