From b13e9c4e3d603955f92c1542a5e86c740f43f33e Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Sun, 27 Dec 2020 21:58:39 +0100 Subject: [PATCH] tests/fuzzers: fix false positive in bitutil fuzzer (#22076) --- tests/fuzzers/bitutil/compress_fuzz.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/fuzzers/bitutil/compress_fuzz.go b/tests/fuzzers/bitutil/compress_fuzz.go index 0b77b2dc9e..5903cf2f93 100644 --- a/tests/fuzzers/bitutil/compress_fuzz.go +++ b/tests/fuzzers/bitutil/compress_fuzz.go @@ -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