From 4f33a5935b36783abb930252e4da487625817ee2 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 15 Sep 2020 13:45:06 -0700 Subject: added test triggering NULL arithmetic with usan described in #847 --- tests/fuzzer.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 4658d79..5ca0d31 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -1055,6 +1055,14 @@ static void FUZ_unitTests(int compressionLevel) FUZ_CHECKTEST(r >= 0, "LZ4_decompress_safe() should fail"); } } + + /* useful to trigger undefined sanitizer */ + DISPLAYLEVEL(3, "LZ4_compress_default() with NULL input \n"); + { int const maxCSize = LZ4_compressBound(0); + int const cSize = LZ4_compress_default(NULL, testCompressed, 0, maxCSize); + FUZ_CHECKTEST(cSize==1 && testCompressed[0]==0, "compressed empty is byte 0"); + } + /* in-place compression test */ DISPLAYLEVEL(3, "in-place compression using LZ4_compress_default() :"); { int const sampleSize = 65 KB; -- cgit v0.12 From da1272979f4b79a7066631335a68512350a071fb Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 15 Sep 2020 14:54:53 -0700 Subject: fix #847 support NULL input without triggering undefined sanitizer --- tests/fuzzer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 5ca0d31..1d8b5f6 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -1059,8 +1059,11 @@ static void FUZ_unitTests(int compressionLevel) /* useful to trigger undefined sanitizer */ DISPLAYLEVEL(3, "LZ4_compress_default() with NULL input \n"); { int const maxCSize = LZ4_compressBound(0); - int const cSize = LZ4_compress_default(NULL, testCompressed, 0, maxCSize); - FUZ_CHECKTEST(cSize==1 && testCompressed[0]==0, "compressed empty is byte 0"); + int const cSize = LZ4_compress_default(NULL, testCompressed, 0, maxCSize); + FUZ_CHECKTEST(!(cSize==1 && testCompressed[0]==0), + "compressing empty should give byte 0" + " (maxCSize == %u) (cSize == %u)", + (unsigned)maxCSize, (unsigned)cSize); } /* in-place compression test */ -- cgit v0.12