diff options
author | Yann Collet <cyan@fb.com> | 2018-02-05 23:18:00 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2018-02-05 23:19:00 (GMT) |
commit | 20e969e5793aa6773593df8768d068a1ae13f746 (patch) | |
tree | 3312235ef8e3a313d1d5ca2aa51b2941d9f66cdd /tests | |
parent | e3f73fa6a6865ca3828a810dc9e45ff616d44681 (diff) | |
download | lz4-20e969e5793aa6773593df8768d068a1ae13f746.zip lz4-20e969e5793aa6773593df8768d068a1ae13f746.tar.gz lz4-20e969e5793aa6773593df8768d068a1ae13f746.tar.bz2 |
fuzzer: added low address compression test
is expected to work on linux+gcc only.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fuzzer.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/fuzzer.c b/tests/fuzzer.c index c134fe3..9415e94 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -240,6 +240,42 @@ _overflowError: } +#ifdef __unix__ /* is expected to be triggered on linux+gcc */ + +#include <sys/mman.h> /* mmap */ + +static void* FUZ_createLowAddr(size_t size) +{ + void* const lowBuff = mmap((void*)(0x1000), size, + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + DISPLAYLEVEL(2, "generating low buffer at address %p \n", lowBuff); + return lowBuff; +} + +static void FUZ_freeLowAddr(void* buffer, size_t size) +{ + if (munmap(buffer, size)) { + perror("fuzzer: freeing low address buffer"); + abort(); + } +} + +#else + +static void* FUZ_createLowAddr(size_t size) +{ + return malloc(size); +} + +static void FUZ_freeLowAddr(void* buffer, size_t size) +{ + (void)size; + free(buffer); +} + +#endif + /*! FUZ_findDiff() : * find the first different byte between buff1 and buff2. * presumes buff1 != buff2. @@ -266,6 +302,8 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c size_t const compressedBufferSize = LZ4_compressBound(FUZ_MAX_BLOCK_SIZE); char* const compressedBuffer = (char*)malloc(compressedBufferSize); char* const decodedBuffer = (char*)malloc(FUZ_MAX_DICT_SIZE + FUZ_MAX_BLOCK_SIZE); + size_t const labSize = 96 KB; + void* const lowAddrBuffer = FUZ_createLowAddr(labSize); void* const stateLZ4 = malloc(LZ4_sizeofState()); void* const stateLZ4HC = malloc(LZ4_sizeofStateHC()); LZ4_stream_t LZ4dict; @@ -306,7 +344,7 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c int const dictSizeRand = FUZ_rand(&randState) % FUZ_MAX_DICT_SIZE; int const dictSize = MIN(dictSizeRand, blockStart); int const compressionLevel = FUZ_rand(&randState) % (LZ4HC_CLEVEL_MAX+1); - char* const block = ((char*)CNBuffer) + blockStart; + const char* block = ((char*)CNBuffer) + blockStart; const char* dict = block - dictSize; int compressedSize, HCcompressedSize; int blockContinueCompressedSize; @@ -317,6 +355,11 @@ static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double c FUZ_displayUpdate(cycleNb); /* Compression tests */ + if ( ((FUZ_rand(&randState) & 63) == 2) + && ((size_t)blockSize < labSize) ) { + memcpy(lowAddrBuffer, block, blockSize); + block = lowAddrBuffer; + } /* Test compression destSize */ FUZ_DISPLAYTEST; @@ -705,6 +748,7 @@ _exit: free(CNBuffer); free(compressedBuffer); free(decodedBuffer); + FUZ_freeLowAddr(lowAddrBuffer, labSize); free(stateLZ4); free(stateLZ4HC); return result; |