From a4f1635b0a29580628c22fbccfd68bda122453bb Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 5 Apr 2019 11:47:06 -0700 Subject: [PATCH] fuzzer: fixed strict c99 with mmap+MAP_ANONYMOUS --- tests/frametest.c | 9 ++++----- tests/fuzzer.c | 4 +--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/frametest.c b/tests/frametest.c index 14906a0..fa005db 100644 --- a/tests/frametest.c +++ b/tests/frametest.c @@ -270,7 +270,7 @@ int basicTests(U32 seed, double compressibility) if (decResult != 0) goto _output_error; /* should finish now */ op += oSize; if (op>oend) { DISPLAY("decompression write overflow \n"); goto _output_error; } - { U64 const crcDest = XXH64(decodedBuffer, op-ostart, 1); + { U64 const crcDest = XXH64(decodedBuffer, (size_t)(op-ostart), 1); if (crcDest != crcOrig) goto _output_error; } } @@ -309,7 +309,6 @@ int basicTests(U32 seed, double compressibility) iSize = 15 - iSize; CHECK( LZ4F_getFrameInfo(dCtx, &fi, ip, &iSize) ); DISPLAYLEVEL(3, " correctly decoded \n"); - ip += iSize; } DISPLAYLEVEL(3, "Decode a buggy input : "); @@ -337,7 +336,7 @@ int basicTests(U32 seed, double compressibility) const BYTE* ip = (const BYTE*) compressedBuffer; const BYTE* const iend = ip + cSize; while (ip < iend) { - size_t oSize = oend-op; + size_t oSize = (size_t)(oend-op); size_t iSize = 1; CHECK( LZ4F_decompress(dCtx, op, &oSize, ip, &iSize, NULL) ); op += oSize; @@ -380,8 +379,8 @@ int basicTests(U32 seed, double compressibility) while (ip < iend) { unsigned const nbBits = FUZ_rand(&randState) % maxBits; size_t iSize = (FUZ_rand(&randState) & ((1< (size_t)(iend-ip)) iSize = iend-ip; + size_t oSize = (size_t)(oend-op); + if (iSize > (size_t)(iend-ip)) iSize = (size_t)(iend-ip); CHECK( LZ4F_decompress(dCtx, op, &oSize, ip, &iSize, NULL) ); op += oSize; ip += iSize; diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 6ebbf20..4cc80fa 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -37,6 +37,7 @@ * Dependencies **************************************/ #if defined(__unix__) && !defined(_AIX) /* must be included before platform.h for MAP_ANONYMOUS */ +# define _GNU_SOURCE /* MAP_ANONYMOUS even in -std=c99 mode */ # include /* mmap */ #endif #include "platform.h" /* _CRT_SECURE_NO_WARNINGS */ @@ -47,9 +48,6 @@ #include /* clock_t, clock, CLOCKS_PER_SEC */ #include #include /* INT_MAX */ -#if defined(__unix__) && defined(_AIX) -# include /* mmap */ -#endif #define LZ4_DISABLE_DEPRECATE_WARNINGS /* LZ4_decompress_fast */ #define LZ4_STATIC_LINKING_ONLY