30 # pragma warning(disable : 4127)
31 # pragma warning(disable : 4146)
32 # pragma warning(disable : 4310)
39 #if defined(__unix__) && !defined(_AIX)
42 # include <sys/mman.h>
54 # include <sys/mman.h>
57 #define LZ4_DISABLE_DEPRECATE_WARNINGS
58 #define LZ4_STATIC_LINKING_ONLY
60 #define LZ4_HC_STATIC_LINKING_ONLY
62 #define XXH_STATIC_LINKING_ONLY
69 #if !defined(__cplusplus) && !(defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) )
77 #define NB_ATTEMPTS (1<<16)
78 #define COMPRESSIBLE_NOISE_LENGTH (1 << 21)
79 #define FUZ_MAX_BLOCK_SIZE (1 << 17)
80 #define FUZ_MAX_DICT_SIZE (1 << 15)
81 #define FUZ_COMPRESSIBILITY_DEFAULT 60
82 #define PRIME1 2654435761U
83 #define PRIME2 2246822519U
84 #define PRIME3 3266489917U
94 #define DISPLAY(...) fprintf(stdout, __VA_ARGS__)
95 #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); }
98 #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
106 return clock() - clockStart;
112 static const clock_t g_refreshRate = CLOCKS_PER_SEC / 5;
122 return ((u32 << nbBits) | (u32 >> (32 - nbBits)));
128 if (v32==0)
return 0;
129 while (v32) { v32 >>= 1; nbBits++; }
144 #define FUZ_RAND15BITS ((FUZ_rand(seed) >> 3) & 32767)
145 #define FUZ_RANDLENGTH ( ((FUZ_rand(seed) >> 7) & 3) ? (FUZ_rand(seed) % 15) : (FUZ_rand(seed) % 510) + 15)
150 U32 const P32 = (
U32)(32768 * proba);
156 while (
pos < bufferSize) {
177 #define MAX_NB_BUFF_I134 150
178 #define BLOCKSIZE_I134 (32 MB)
192 if (
sizeof(
void*)==8) {
193 DISPLAY(
"64 bits mode : no overflow \n");
200 if ((!buffers[0]) || (!buffers[1])) {
202 DISPLAY(
"not enough memory for tests \n");
207 DISPLAY(
"%3i \b\b\b\b", nbBuff); fflush(stdout);
209 if (buffers[nbBuff]==
NULL)
goto _endOfTests;
212 DISPLAY(
"high address detected : ");
217 {
size_t const sizeToGenerateOverflow = (
size_t)(- ((
uintptr_t)buffers[nbBuff-1]) + 512);
218 int const nbOf255 = (
int)((sizeToGenerateOverflow / 255) + 1);
219 char*
const input = buffers[nbBuff-1];
220 char*
output = buffers[nbBuff];
222 input[0] = (char)0xF0;
223 input[1] = (char)0xFF;
224 input[2] = (char)0xFF;
225 input[3] = (char)0xFF;
226 {
int u;
for(u = 4; u <= nbOf255+4; u++)
input[u] = (
char)0xff; }
228 if (
r>0) {
DISPLAY(
"LZ4_decompress_safe = %i \n",
r);
goto _overflowError; }
229 input[0] = (char)0x1F;
230 input[1] = (char)0x01;
231 input[2] = (char)0x01;
232 input[3] = (char)0x00;
234 if (
r>0) {
DISPLAY(
"LZ4_decompress_safe = %i \n",
r);
goto _overflowError; }
236 output = buffers[nbBuff-2];
237 input[0] = (char)0xF0;
238 input[1] = (char)0xFF;
239 input[2] = (char)0xFF;
240 input[3] = (char)0xFF;
242 if (
r>0)
goto _overflowError;
243 input[0] = (char)0x1F;
244 input[1] = (char)0x01;
245 input[2] = (char)0x01;
246 input[3] = (char)0x00;
248 if (
r>0)
goto _overflowError;
254 {
int i;
for (
i=0 ;
i<nbBuff;
i++)
free(buffers[
i]); }
255 if (!highAddress)
DISPLAY(
"high address not possible \n");
256 else DISPLAY(
"all overflows correctly detected \n");
260 DISPLAY(
"Address space overflow error !! \n");
269 void*
const lowBuff =
mmap((
void*)(0x1000),
size,
272 DISPLAYLEVEL(2,
"generating low buffer at address %p \n", lowBuff);
279 perror(
"fuzzer: freeing low address buffer");
311 while (
b1[u]==
b2[u]) u++;
312 DISPLAY(
"\nWrong Byte at position %u \n", (
unsigned)u);
316 static int FUZ_test(
U32 seed,
U32 nbCycles,
const U32 startCycle,
const double compressibility,
U32 duration_s)
318 unsigned long long bytes = 0;
319 unsigned long long cbytes = 0;
320 unsigned long long hcbytes = 0;
321 unsigned long long ccbytes = 0;
324 char*
const compressedBuffer = (
char*)
malloc(compressedBufferSize);
326 size_t const labSize = 96
KB;
332 U32 coreRandState = seed;
333 clock_t const clockStart = clock();
334 clock_t const clockDuration = (
clock_t)duration_s * CLOCKS_PER_SEC;
338 # define EXIT_MSG(...) { \
339 printf("Test %u : ", testNb); printf(__VA_ARGS__); \
340 printf(" (seed %u, cycle %u) \n", seed, cycleNb); \
344 # define FUZ_CHECKTEST(cond, ...) if (cond) { EXIT_MSG(__VA_ARGS__) }
346 # define FUZ_DISPLAYTEST(...) { \
348 if (g_displayLevel>=4) { \
349 printf("\r%4u - %2u :", cycleNb, testNb); \
350 printf(" " __VA_ARGS__); \
357 if(!CNBuffer || !compressedBuffer || !decodedBuffer || !LZ4dictHC) {
358 DISPLAY(
"Not enough memory to start fuzzer tests");
362 {
U32 randState = coreRandState ^
PRIME3;
367 for (cycleNb = 0; cycleNb < startCycle; cycleNb++)
371 for (cycleNb = startCycle;
379 int const dictSize =
MIN(dictSizeRand, blockStart - 1);
381 const char* block = ((
char*)CNBuffer) + blockStart;
382 const char* dict = block - dictSize;
384 int blockContinueCompressedSize;
385 U32 const crcOrig =
XXH32(block, (
size_t)blockSize, 0);
391 if ( ((
FUZ_rand(&randState) & 63) == 2)
392 && ((
size_t)blockSize < labSize) ) {
393 memcpy(lowAddrBuffer, block, blockSize);
394 block = (
const char*)lowAddrBuffer;
399 {
int cSize,
srcSize = blockSize;
401 char const endCheck = (char)(
FUZ_rand(&randState) & 255);
402 compressedBuffer[targetSize] = endCheck;
404 FUZ_CHECKTEST(cSize > targetSize,
"LZ4_compress_destSize() result larger than dst buffer !");
405 FUZ_CHECKTEST(compressedBuffer[targetSize] != endCheck,
"LZ4_compress_destSize() overwrite dst buffer !");
407 DISPLAYLEVEL(5,
"destSize : %7i/%7i; content%7i/%7i ", cSize, targetSize,
srcSize, blockSize);
411 char const canary = (char)(
FUZ_rand(&randState) & 255);
412 FUZ_CHECKTEST((cSize==0),
"LZ4_compress_destSize() compression failed");
414 decodedBuffer[
srcSize] = canary;
416 FUZ_CHECKTEST(dSize<0,
"LZ4_decompress_safe() failed on data compressed by LZ4_compress_destSize");
417 FUZ_CHECKTEST(dSize!=
srcSize,
"LZ4_decompress_safe() failed : did not fully decompressed data");
419 FUZ_CHECKTEST(decodedBuffer[
srcSize] != canary,
"LZ4_decompress_safe() overwrite dst buffer !");
421 FUZ_CHECKTEST(crcDec!=crcBase,
"LZ4_decompress_safe() corrupted decoded data");
428 {
int cSize,
srcSize = blockSize;
430 char const endCheck = (char)(
FUZ_rand(&randState) & 255);
433 compressedBuffer[targetSize] = endCheck;
435 DISPLAYLEVEL(5,
"LZ4_compress_HC_destSize(%i): destSize : %7i/%7i; content%7i/%7i ",
438 FUZ_CHECKTEST(cSize > targetSize,
"LZ4_compress_HC_destSize() result larger than dst buffer !");
439 FUZ_CHECKTEST(compressedBuffer[targetSize] != endCheck,
"LZ4_compress_HC_destSize() overwrite dst buffer !");
444 char const canary = (char)(
FUZ_rand(&randState) & 255);
445 FUZ_CHECKTEST((cSize==0),
"LZ4_compress_HC_destSize() compression failed");
447 decodedBuffer[
srcSize] = canary;
449 FUZ_CHECKTEST(dSize<0,
"LZ4_decompress_safe failed (%i) on data compressed by LZ4_compressHC_destSize", dSize);
450 FUZ_CHECKTEST(dSize!=
srcSize,
"LZ4_decompress_safe failed : decompressed %i bytes, was supposed to decompress %i bytes", dSize,
srcSize);
454 FUZ_CHECKTEST(crcDec!=crcBase,
"LZ4_decompress_safe() corrupted decoded data");
462 FUZ_CHECKTEST(HCcompressedSize==0,
"LZ4_compress_HC() failed");
473 FUZ_CHECKTEST(
r==0,
"LZ4_compress_HC_extStateHC_fastReset() failed");
484 FUZ_CHECKTEST(
r==0,
"LZ4_compress_fast_extState_fastReset() failed"); }
502 FUZ_CHECKTEST(
r<0,
"LZ4_decompress_fast failed despite correct space");
505 {
U32 const crcCheck =
XXH32(decodedBuffer, (
size_t)blockSize, 0);
506 FUZ_CHECKTEST(crcCheck!=crcOrig,
"LZ4_decompress_fast corrupted decoded data");
510 FUZ_DISPLAYTEST(
"LZ4_decompress_fast() with output buffer 1-byte too short");
511 decodedBuffer[blockSize-1] = 0;
513 FUZ_CHECKTEST(
r>=0,
"LZ4_decompress_fast should have failed, due to Output Size being too small");
515 FUZ_CHECKTEST(decodedBuffer[blockSize-1]!=0,
"LZ4_decompress_fast overrun specified output buffer");
520 FUZ_CHECKTEST(
r>=0,
"LZ4_decompress_fast should have failed, due to Output Size being too large");
525 decodedBuffer[blockSize] = 0;
527 FUZ_CHECKTEST(
r<0,
"LZ4_decompress_safe failed despite sufficient space");
528 FUZ_CHECKTEST(
r!=blockSize,
"LZ4_decompress_safe did not regenerate original data");
530 FUZ_CHECKTEST(decodedBuffer[blockSize],
"LZ4_decompress_safe overrun specified output buffer size");
531 {
U32 const crcCheck =
XXH32(decodedBuffer, (
size_t)blockSize, 0);
532 FUZ_CHECKTEST(crcCheck!=crcOrig,
"LZ4_decompress_safe corrupted decoded data");
537 decodedBuffer[blockSize] = 0;
538 decodedBuffer[blockSize+1] = 0;
540 FUZ_CHECKTEST(
r<0,
"LZ4_decompress_safe failed despite amply sufficient space");
541 FUZ_CHECKTEST(
r!=blockSize,
"LZ4_decompress_safe did not regenerate original data");
543 FUZ_CHECKTEST(decodedBuffer[blockSize+1],
"LZ4_decompress_safe overrun specified output buffer size");
544 {
U32 const crcCheck =
XXH32(decodedBuffer, (
size_t)blockSize, 0);
545 FUZ_CHECKTEST(crcCheck!=crcOrig,
"LZ4_decompress_safe corrupted decoded data");
550 decodedBuffer[blockSize-1] = 0;
552 FUZ_CHECKTEST(
r>=0,
"LZ4_decompress_safe should have failed, due to Output Size being one byte too short");
554 FUZ_CHECKTEST(decodedBuffer[blockSize-1],
"LZ4_decompress_safe overrun specified output buffer size");
559 decodedBuffer[blockSize-10] = 0;
561 FUZ_CHECKTEST(
r>=0,
"LZ4_decompress_safe should have failed, due to Output Size being 10 bytes too short");
563 FUZ_CHECKTEST(decodedBuffer[blockSize-10],
"LZ4_decompress_safe overrun specified output buffer size");
573 {
U32 const nbBits =
FUZ_rand(&randState) % maxNbBits;
574 size_t const mask = (1<<nbBits) - 1;
580 {
U32 const nbBitsCodes =
FUZ_rand(&randState) % maxNbBits;
581 U32 const nbBits = nbBitsCodes ? nbBitsCodes-1 : 0;
582 size_t const mask = (1<<nbBits) - 1;
583 size_t const rNoiseLength = (
FUZ_rand(&randState) &
mask) + 1;
586 memcpy(cBuffer_exact +
pos, (
const char*)CNBuffer + noiseStart, noiseLength);
592 {
U32 const endMark = 0xA9B1C3D6;
593 memcpy(decodedBuffer+blockSize, &endMark,
sizeof(endMark));
596 FUZ_CHECKTEST(decompressResult > blockSize,
"LZ4_decompress_safe on noisy src : result is too large : %u > %u (dst buffer)", (
unsigned)decompressResult, (
unsigned)blockSize);
598 {
U32 endCheck;
memcpy(&endCheck, decodedBuffer+blockSize,
sizeof(endCheck));
599 FUZ_CHECKTEST(endMark!=endCheck,
"LZ4_decompress_safe on noisy src : dst buffer overflow");
608 FUZ_CHECKTEST(
r>=0,
"LZ4_decompress_safe should have failed, due to input size being one byte too short (blockSize=%i, result=%i, compressedSize=%i)", blockSize,
r,
compressedSize);
613 decodedBuffer[blockSize] = 0;
615 FUZ_CHECKTEST(
r>=0,
"LZ4_decompress_safe should have failed, due to input size being too large");
617 FUZ_CHECKTEST(decodedBuffer[blockSize],
"LZ4_decompress_safe overrun specified output buffer size");
621 {
size_t const missingOutBytes =
FUZ_rand(&randState) % (
unsigned)blockSize;
622 int const targetSize = (
int)((
size_t)blockSize - missingOutBytes);
623 size_t const extraneousInBytes =
FUZ_rand(&randState) % 2;
625 char const sentinel = decodedBuffer[targetSize] = block[targetSize] ^ 0x5A;
627 FUZ_CHECKTEST(decResult<0,
"LZ4_decompress_safe_partial failed despite valid input data (error:%i)", decResult);
628 FUZ_CHECKTEST(decResult != targetSize,
"LZ4_decompress_safe_partial did not regenerated required amount of data (%i < %i <= %i)", decResult, targetSize, blockSize);
629 FUZ_CHECKTEST(decodedBuffer[targetSize] != sentinel,
"LZ4_decompress_safe_partial overwrite beyond requested size (though %i <= %i <= %i)", decResult, targetSize, blockSize);
630 FUZ_CHECKTEST(memcmp(block, decodedBuffer, (
size_t)targetSize),
"LZ4_decompress_safe_partial: corruption detected in regenerated data");
636 FUZ_DISPLAYTEST(
"test LZ4_compress_default() with output buffer just the right size");
638 FUZ_CHECKTEST(ret==0,
"LZ4_compress_default() failed despite sufficient space");
641 FUZ_DISPLAYTEST(
"test LZ4_compress_fast_extState() with output buffer just the right size");
643 FUZ_CHECKTEST(ret==0,
"LZ4_compress_fast_extState() failed despite sufficient space");
646 FUZ_DISPLAYTEST(
"test LZ4_compress_HC() with output buffer just the right size");
648 FUZ_CHECKTEST(ret==0,
"LZ4_compress_HC() failed despite sufficient space");
651 FUZ_DISPLAYTEST(
"test LZ4_compress_HC_extStateHC() with output buffer just the right size");
653 FUZ_CHECKTEST(ret==0,
"LZ4_compress_HC_extStateHC() failed despite sufficient space");
656 FUZ_DISPLAYTEST(
"test LZ4_compress_default() with output buffer a bit too short");
657 {
int missingBytes = (
FUZ_rand(&randState) % 0x3F) + 1;
659 missingBytes += !missingBytes;
662 FUZ_CHECKTEST(cSize,
"LZ4_compress_default should have failed (output buffer too small by %i byte)", missingBytes);
664 FUZ_CHECKTEST(compressedBuffer[
compressedSize-missingBytes],
"LZ4_compress_default overran output buffer ! (%i missingBytes)", missingBytes)
668 FUZ_DISPLAYTEST(
"test LZ4_compress_HC() with output buffer a bit too short");
669 {
int missingBytes = (
FUZ_rand(&randState) % 0x3F) + 1;
670 if (missingBytes >= HCcompressedSize) missingBytes = HCcompressedSize-1;
671 missingBytes += !missingBytes;
672 compressedBuffer[HCcompressedSize-missingBytes] = 0;
674 FUZ_CHECKTEST(hcSize,
"LZ4_compress_HC should have failed (output buffer too small by %i byte)", missingBytes);
676 FUZ_CHECKTEST(compressedBuffer[HCcompressedSize-missingBytes],
"LZ4_compress_HC overran output buffer ! (%i missingBytes)", missingBytes)
685 FUZ_DISPLAYTEST(
"test LZ4_compress_fast_continue() with dictionary of size %i", dictSize);
690 FUZ_CHECKTEST(blockContinueCompressedSize==0,
"LZ4_compress_fast_continue failed");
694 FUZ_DISPLAYTEST(
"test LZ4_decompress_fast_usingDict() with dictionary as prefix");
695 memcpy(decodedBuffer, dict, dictSize);
697 FUZ_CHECKTEST(ret!=blockContinueCompressedSize,
"LZ4_decompress_fast_usingDict did not read all compressed block input");
698 {
U32 const crcCheck =
XXH32(decodedBuffer+dictSize, (
size_t)blockSize, 0);
699 if (crcCheck!=crcOrig) {
701 EXIT_MSG(
"LZ4_decompress_fast_usingDict corrupted decoded data (dict %i)", dictSize);
705 ret =
LZ4_decompress_safe_usingDict(compressedBuffer, decodedBuffer+dictSize, blockContinueCompressedSize, blockSize, decodedBuffer, dictSize);
706 FUZ_CHECKTEST(ret!=blockSize,
"LZ4_decompress_safe_usingDict did not regenerate original data");
707 {
U32 const crcCheck =
XXH32(decodedBuffer+dictSize, (
size_t)blockSize, 0);
708 FUZ_CHECKTEST(crcCheck!=crcOrig,
"LZ4_decompress_safe_usingDict corrupted decoded data");
712 FUZ_DISPLAYTEST(
"test LZ4_compress_fast_continue(), with non-contiguous dictionary");
714 if (dict < (
char*)CNBuffer) dict = (
char*)CNBuffer;
716 blockContinueCompressedSize =
LZ4_compress_fast_continue(&LZ4dictBody, block, compressedBuffer, blockSize, (
int)compressedBufferSize, 1);
717 FUZ_CHECKTEST(blockContinueCompressedSize==0,
"LZ4_compress_fast_continue failed");
719 FUZ_DISPLAYTEST(
"LZ4_compress_fast_continue() with dictionary and output buffer too short by one byte");
722 FUZ_CHECKTEST(ret>0,
"LZ4_compress_fast_continue using ExtDict should fail : one missing byte for output buffer : %i written, %i buffer", ret, blockContinueCompressedSize);
724 FUZ_DISPLAYTEST(
"test LZ4_compress_fast_continue() with dictionary loaded with LZ4_loadDict()");
725 DISPLAYLEVEL(5,
" compress %i bytes from buffer(%p) into dst(%p) using dict(%p) of size %i \n",
726 blockSize, (
const void *)block, (
void *)decodedBuffer, (
const void *)dict, dictSize);
729 FUZ_CHECKTEST(ret!=blockContinueCompressedSize,
"LZ4_compress_limitedOutput_compressed size is different (%i != %i)", ret, blockContinueCompressedSize);
730 FUZ_CHECKTEST(ret<=0,
"LZ4_compress_fast_continue should work : enough size available within output buffer");
733 FUZ_DISPLAYTEST(
"test LZ4_decompress_fast_usingDict() with dictionary as extDict");
734 DISPLAYLEVEL(5,
" decoding %i bytes from buffer(%p) using dict(%p) of size %i \n",
735 blockSize, (
void *)decodedBuffer, (
const void *)dict, dictSize);
736 decodedBuffer[blockSize] = 0;
738 FUZ_CHECKTEST(ret!=blockContinueCompressedSize,
"LZ4_decompress_fast_usingDict did not read all compressed block input");
739 FUZ_CHECKTEST(decodedBuffer[blockSize],
"LZ4_decompress_fast_usingDict overrun specified output buffer size");
740 {
U32 const crcCheck =
XXH32(decodedBuffer, (
size_t)blockSize, 0);
741 if (crcCheck!=crcOrig) {
743 EXIT_MSG(
"LZ4_decompress_fast_usingDict corrupted decoded data (dict %i)", dictSize);
747 decodedBuffer[blockSize] = 0;
749 FUZ_CHECKTEST(ret!=blockSize,
"LZ4_decompress_safe_usingDict did not regenerate original data");
750 FUZ_CHECKTEST(decodedBuffer[blockSize],
"LZ4_decompress_safe_usingDict overrun specified output buffer size");
751 {
U32 const crcCheck =
XXH32(decodedBuffer, (
size_t)blockSize, 0);
752 FUZ_CHECKTEST(crcCheck!=crcOrig,
"LZ4_decompress_safe_usingDict corrupted decoded data");
756 decodedBuffer[blockSize-1] = 0;
758 FUZ_CHECKTEST(ret>=0,
"LZ4_decompress_fast_usingDict should have failed : wrong original size (-1 byte)");
759 FUZ_CHECKTEST(decodedBuffer[blockSize-1],
"LZ4_decompress_fast_usingDict overrun specified output buffer size");
762 decodedBuffer[blockSize-1] = 0;
764 FUZ_CHECKTEST(ret>=0,
"LZ4_decompress_safe_usingDict should have failed : not enough output size (-1 byte)");
765 FUZ_CHECKTEST(decodedBuffer[blockSize-1],
"LZ4_decompress_safe_usingDict overrun specified output buffer size");
768 {
int const missingBytes = (
FUZ_rand(&randState) & 0xF) + 2;
769 if (blockSize > missingBytes) {
770 decodedBuffer[blockSize-missingBytes] = 0;
772 FUZ_CHECKTEST(ret>=0,
"LZ4_decompress_safe_usingDict should have failed : output buffer too small (-%i byte)", missingBytes);
773 FUZ_CHECKTEST(decodedBuffer[blockSize-missingBytes],
"LZ4_decompress_safe_usingDict overrun specified output buffer size (-%i byte) (blockSize=%i)", missingBytes, blockSize);
784 FUZ_CHECKTEST(expectedSize<=0,
"LZ4_compress_fast_continue reference compression for extDictCtx should have succeeded");
785 expectedCrc =
XXH32(compressedBuffer, (
size_t)expectedSize, 0);
787 FUZ_DISPLAYTEST(
"LZ4_compress_fast_continue() after LZ4_attach_dictionary()");
792 FUZ_CHECKTEST(blockContinueCompressedSize==0,
"LZ4_compress_fast_continue using extDictCtx failed");
799 FUZ_CHECKTEST(blockContinueCompressedSize != expectedSize,
"LZ4_compress_fast_continue using extDictCtx produced different-sized output (%d expected vs %d actual)", expectedSize, blockContinueCompressedSize);
800 FUZ_CHECKTEST(
XXH32(compressedBuffer, (
size_t)blockContinueCompressedSize, 0) != expectedCrc,
"LZ4_compress_fast_continue using extDictCtx produced different output");
802 FUZ_DISPLAYTEST(
"LZ4_compress_fast_continue() after LZ4_attach_dictionary(), but output buffer is 1 byte too short");
806 FUZ_CHECKTEST(ret>0,
"LZ4_compress_fast_continue using extDictCtx should fail : one missing byte for output buffer : %i written, %i buffer", ret, blockContinueCompressedSize);
813 FUZ_CHECKTEST(ret!=blockContinueCompressedSize,
"LZ4_compress_limitedOutput_compressed size is different (%i != %i)", ret, blockContinueCompressedSize);
814 FUZ_CHECKTEST(ret<=0,
"LZ4_compress_fast_continue using extDictCtx should work : enough size available within output buffer");
815 FUZ_CHECKTEST(ret != expectedSize,
"LZ4_compress_fast_continue using extDictCtx produced different-sized output");
816 FUZ_CHECKTEST(
XXH32(compressedBuffer, (
size_t)ret, 0) != expectedCrc,
"LZ4_compress_fast_continue using extDictCtx produced different output");
822 FUZ_CHECKTEST(ret!=blockContinueCompressedSize,
"LZ4_compress_limitedOutput_compressed size is different (%i != %i)", ret, blockContinueCompressedSize);
823 FUZ_CHECKTEST(ret<=0,
"LZ4_compress_fast_continue using extDictCtx with re-used context should work : enough size available within output buffer");
824 FUZ_CHECKTEST(ret != expectedSize,
"LZ4_compress_fast_continue using extDictCtx produced different-sized output");
825 FUZ_CHECKTEST(
XXH32(compressedBuffer, (
size_t)ret, 0) != expectedCrc,
"LZ4_compress_fast_continue using extDictCtx produced different output");
830 decodedBuffer[blockSize] = 0;
832 FUZ_CHECKTEST(ret!=blockContinueCompressedSize,
"LZ4_decompress_fast_usingDict did not read all compressed block input");
833 FUZ_CHECKTEST(decodedBuffer[blockSize],
"LZ4_decompress_fast_usingDict overrun specified output buffer size");
834 {
U32 const crcCheck =
XXH32(decodedBuffer, (
size_t)blockSize, 0);
835 if (crcCheck!=crcOrig) {
837 EXIT_MSG(
"LZ4_decompress_fast_usingDict corrupted decoded data (dict %i)", dictSize);
841 decodedBuffer[blockSize] = 0;
843 FUZ_CHECKTEST(ret!=blockSize,
"LZ4_decompress_safe_usingDict did not regenerate original data");
844 FUZ_CHECKTEST(decodedBuffer[blockSize],
"LZ4_decompress_safe_usingDict overrun specified output buffer size");
845 {
U32 const crcCheck =
XXH32(decodedBuffer, (
size_t)blockSize, 0);
846 FUZ_CHECKTEST(crcCheck!=crcOrig,
"LZ4_decompress_safe_usingDict corrupted decoded data");
850 decodedBuffer[blockSize-1] = 0;
852 FUZ_CHECKTEST(ret>=0,
"LZ4_decompress_fast_usingDict should have failed : wrong original size (-1 byte)");
853 FUZ_CHECKTEST(decodedBuffer[blockSize-1],
"LZ4_decompress_fast_usingDict overrun specified output buffer size");
856 decodedBuffer[blockSize-1] = 0;
858 FUZ_CHECKTEST(ret>=0,
"LZ4_decompress_safe_usingDict should have failed : not enough output size (-1 byte)");
859 FUZ_CHECKTEST(decodedBuffer[blockSize-1],
"LZ4_decompress_safe_usingDict overrun specified output buffer size");
861 FUZ_DISPLAYTEST(
"LZ4_decompress_safe_usingDict with a too small output buffer");
862 {
int const missingBytes = (
FUZ_rand(&randState) & 0xF) + 2;
863 if (blockSize > missingBytes) {
864 decodedBuffer[blockSize-missingBytes] = 0;
866 FUZ_CHECKTEST(ret>=0,
"LZ4_decompress_safe_usingDict should have failed : output buffer too small (-%i byte)", missingBytes);
867 FUZ_CHECKTEST(decodedBuffer[blockSize-missingBytes],
"LZ4_decompress_safe_usingDict overrun specified output buffer size (-%i byte) (blockSize=%i)", missingBytes, blockSize);
871 FUZ_DISPLAYTEST(
"LZ4_compress_HC_continue with an external dictionary");
873 if (dict < (
char*)CNBuffer) dict = (
char*)CNBuffer;
876 blockContinueCompressedSize =
LZ4_compress_HC_continue(LZ4dictHC, block, compressedBuffer, blockSize, (
int)compressedBufferSize);
877 FUZ_CHECKTEST(blockContinueCompressedSize==0,
"LZ4_compress_HC_continue failed");
880 FUZ_DISPLAYTEST(
"LZ4_compress_HC_continue with same external dictionary, but output buffer 1 byte too short");
883 FUZ_CHECKTEST(ret>0,
"LZ4_compress_HC_continue using ExtDict should fail : one missing byte for output buffer (expected %i, but result=%i)", blockContinueCompressedSize, ret);
886 FUZ_DISPLAYTEST(
"LZ4_compress_HC_continue with same external dictionary, and output buffer exactly the right size");
889 FUZ_CHECKTEST(ret!=blockContinueCompressedSize,
"LZ4_compress_HC_continue size is different : ret(%i) != expected(%i)", ret, blockContinueCompressedSize);
890 FUZ_CHECKTEST(ret<=0,
"LZ4_compress_HC_continue should work : enough size available within output buffer");
894 decodedBuffer[blockSize] = 0;
896 FUZ_CHECKTEST(ret!=blockSize,
"LZ4_decompress_safe_usingDict did not regenerate original data");
897 FUZ_CHECKTEST(decodedBuffer[blockSize],
"LZ4_decompress_safe_usingDict overrun specified output buffer size");
898 {
U32 const crcCheck =
XXH32(decodedBuffer, (
size_t)blockSize, 0);
899 if (crcCheck!=crcOrig) {
901 EXIT_MSG(
"LZ4_decompress_safe_usingDict corrupted decoded data");
912 FUZ_CHECKTEST(blockContinueCompressedSize==0,
"LZ4_compress_HC_continue with ExtDictCtx failed");
919 FUZ_CHECKTEST(ret>0,
"LZ4_compress_HC_continue using ExtDictCtx should fail : one missing byte for output buffer (%i != %i)", ret, blockContinueCompressedSize);
926 FUZ_CHECKTEST(ret!=blockContinueCompressedSize,
"LZ4_compress_HC_continue using ExtDictCtx size is different (%i != %i)", ret, blockContinueCompressedSize);
927 FUZ_CHECKTEST(ret<=0,
"LZ4_compress_HC_continue using ExtDictCtx should work : enough size available within output buffer");
934 FUZ_CHECKTEST(ret!=blockContinueCompressedSize,
"LZ4_compress_HC_continue using ExtDictCtx and fast reset size is different (%i != %i)",
935 ret, blockContinueCompressedSize);
936 FUZ_CHECKTEST(ret<=0,
"LZ4_compress_HC_continue using ExtDictCtx and fast reset should work : enough size available within output buffer");
943 decodedBuffer[blockSize] = 0;
945 FUZ_CHECKTEST(ret!=blockSize,
"LZ4_decompress_safe_usingDict did not regenerate original data");
946 FUZ_CHECKTEST(decodedBuffer[blockSize],
"LZ4_decompress_safe_usingDict overrun specified output buffer size");
947 {
U32 const crcCheck =
XXH32(decodedBuffer, (
size_t)blockSize, 0);
948 if (crcCheck!=crcOrig) {
950 EXIT_MSG(
"LZ4_decompress_safe_usingDict corrupted decoded data");
955 {
int const availableSpace = (
int)(
FUZ_rand(&randState) % (
U32)blockSize) + 5;
956 int consumedSize = blockSize;
961 DISPLAYLEVEL(5,
" LZ4_compress_HC_continue_destSize : compressed %6i/%6i into %6i/%6i at cLevel=%i \n",
962 consumedSize, blockSize, blockContinueCompressedSize, availableSpace,
compressionLevel);
963 FUZ_CHECKTEST(blockContinueCompressedSize==0,
"LZ4_compress_HC_continue_destSize failed");
964 FUZ_CHECKTEST(blockContinueCompressedSize > availableSpace,
"LZ4_compress_HC_continue_destSize write overflow");
965 FUZ_CHECKTEST(consumedSize > blockSize,
"LZ4_compress_HC_continue_destSize read overflow");
968 decodedBuffer[consumedSize] = 0;
970 FUZ_CHECKTEST(ret != consumedSize,
"LZ4_decompress_safe_usingDict regenerated %i bytes (%i expected)", ret, consumedSize);
971 FUZ_CHECKTEST(decodedBuffer[consumedSize],
"LZ4_decompress_safe_usingDict overrun specified output buffer size")
972 {
U32 const crcSrc =
XXH32(block, (
size_t)consumedSize, 0);
973 U32 const crcDst =
XXH32(decodedBuffer, (
size_t)consumedSize, 0);
974 if (crcSrc!=crcDst) {
976 EXIT_MSG(
"LZ4_decompress_safe_usingDict corrupted decoded data");
986 assert(HCcompressedSize >= 0);
987 hcbytes += (
unsigned)HCcompressedSize;
988 assert(blockContinueCompressedSize >= 0);
989 ccbytes += (
unsigned)blockContinueCompressedSize;
992 if (nbCycles<=1) nbCycles = cycleNb;
994 printf(
"\r%7u /%7u - ", cycleNb, nbCycles);
995 printf(
"all tests completed successfully \n");
996 printf(
"compression ratio: %0.3f%%\n", (
double)cbytes/
bytes*100);
997 printf(
"HC compression ratio: %0.3f%%\n", (
double)hcbytes/
bytes*100);
998 printf(
"ratio with dict: %0.3f%%\n", (
double)ccbytes/
bytes*100);
1002 free(compressedBuffer);
1003 free(decodedBuffer);
1012 #define testInputSize (196 KB)
1013 #define testCompressedSize (130 KB)
1014 #define ringBufferSize (8 KB)
1018 const unsigned testNb = 0;
1019 const unsigned seed = 0;
1020 const unsigned cycleNb= 0;
1028 if (!testInput || !testCompressed || !testVerify) {
1029 EXIT_MSG(
"not enough memory for FUZ_unitTests");
1037 DISPLAYLEVEL(3,
"LZ4_decompress_safe() with empty input \n");
1041 DISPLAYLEVEL(3,
"LZ4_decompress_safe() with one byte input \n");
1042 {
char const tmp = (char)0xFF;
1047 DISPLAYLEVEL(3,
"LZ4_decompress_safe() with shortcut edge case \n");
1062 DISPLAYLEVEL(3,
"LZ4_compress_default() with NULL input:");
1066 "compressing empty should give byte 0"
1067 " (maxCSize == %i) (cSize == %i) (byte == 0x%02X)",
1068 maxCSize, cSize, testCompressed[0]);
1072 DISPLAYLEVEL(3,
"LZ4_compress_default() with both NULL input and output:");
1075 "compressing into NULL must fail"
1076 " (cSize == %i != 0)", cSize);
1081 DISPLAYLEVEL(3,
"in-place compression using LZ4_compress_default() :");
1082 {
int const sampleSize = 65
KB;
1084 int const outSize = LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCSize);
1085 int const startInputIndex = outSize - sampleSize;
1086 char*
const startInput = testCompressed + startInputIndex;
1090 memcpy(startInput, testInput, sampleSize);
1095 assert(cSize <= maxCSize);
1098 assert(dSize == sampleSize);
1100 FUZ_CHECKTEST(crcCheck != crcOrig,
"LZ4_decompress_safe decompression corruption");
1105 DISPLAYLEVEL(3,
"in-place decompression, limit case:");
1106 {
int const sampleSize = 65
KB;
1109 memset(testInput, 0, 267);
1113 assert(cSize == sampleSize - 1);
1115 {
int const bufferSize = LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(sampleSize);
1116 int const startInputIndex = bufferSize - cSize;
1117 char*
const startInput = testVerify + startInputIndex;
1118 memcpy(startInput, testCompressed, cSize);
1122 assert(dSize == sampleSize);
1124 FUZ_CHECKTEST(crcCheck != crcOrig,
"LZ4_decompress_safe decompression corruption");
1128 DISPLAYLEVEL(3,
"LZ4_initStream with multiple valid alignments : ");
1135 shct*
const shc = (shct*)
malloc(
sizeof(*shc));
1137 memset(shc, 0,
sizeof(*shc));
1138 DISPLAYLEVEL(4,
"state1(%p) state2(%p) state3(%p) LZ4_stream_t size(0x%x): ",
1139 &(shc->state1), &(shc->state2), &(shc->state3), (
unsigned)
sizeof(
LZ4_stream_t));
1144 "hc1+1 (%p) init must fail, due to bad alignment", (
char*)&(shc->state1) + 1 );
1161 FUZ_CHECKTEST(
cs==0,
"LZ4_compress_fast_continue() compression failed!");
1167 FUZ_CHECKTEST(crcOrig!=crcNew,
"LZ4_decompress_safe() decompression corruption");
1177 "LZ4_saveDict() can't save anything into (NULL,0)");
1180 {
char tmp_buffer[240] = { 0 };
1182 "LZ4_saveDict() can't save anything since compression hasn't started");
1190 const U32 maxMessageSizeLog = 10;
1191 const U32 maxMessageSizeMask = (1<<maxMessageSizeLog) - 1;
1192 U32 messageSize = (
FUZ_rand(&randState) & maxMessageSizeMask) + 1;
1207 XXH64_update(&xxhOrig, testInput + iNext, messageSize);
1210 memcpy (ringBuffer + rNext, testInput + iNext, messageSize);
1215 FUZ_CHECKTEST(
r!=(
int)messageSize,
"ringBuffer : LZ4_decompress_safe_continue() test failed"); }
1217 XXH64_update(&xxhNewSafe, testVerify + dNext, messageSize);
1219 FUZ_CHECKTEST(crcOrig!=crcNew,
"LZ4_decompress_safe_continue() decompression corruption"); }
1224 XXH64_update(&xxhNewFast, testVerify + dNext, messageSize);
1226 FUZ_CHECKTEST(crcOrig!=crcNew,
"LZ4_decompress_fast_continue() decompression corruption"); }
1229 iNext += messageSize;
1230 rNext += messageSize;
1231 dNext += messageSize;
1232 messageSize = (
FUZ_rand(&randState) & maxMessageSizeMask) + 1;
1234 if (dNext + messageSize > dBufferSize) dNext = 0;
1238 DISPLAYLEVEL(3,
"LZ4_initStreamHC with multiple valid alignments : ");
1245 shct*
const shc = (shct*)
malloc(
sizeof(*shc));
1247 memset(shc, 0,
sizeof(*shc));
1248 DISPLAYLEVEL(4,
"hc1(%p) hc2(%p) hc3(%p) size(0x%x): ",
1249 &(shc->hc1), &(shc->hc2), &(shc->hc3), (
unsigned)
sizeof(
LZ4_streamHC_t));
1254 "hc1+1 (%p) init must fail, due to bad alignment", (
char*)&(shc->hc1) + 1 );
1277 FUZ_CHECKTEST(result==0,
"LZ4_compressHC_limitedOutput_continue() compression failed");
1283 FUZ_CHECKTEST(crc64!=crcNew,
"LZ4_decompress_safe() decompression corruption");
1294 "LZ4_saveDictHC() can't save anything into (NULL,0)");
1297 {
char tmp_buffer[240] = { 0 };
1299 "LZ4_saveDictHC() can't save anything since compression hasn't started");
1305 {
size_t const blockSize = 1
MB;
1306 size_t const targetSize = 4116;
1307 void*
const block =
malloc(blockSize);
1308 void*
const dstBlock =
malloc(targetSize+1);
1309 BYTE const sentinel = 101;
1313 memset(block, 0, blockSize);
1314 ((
char*)dstBlock)[targetSize] = sentinel;
1322 FUZ_CHECKTEST(result != 4116,
"LZ4_compress_HC_destSize() : "
1323 "compression (%i->%i) must fill dstBuffer (%i) exactly",
1324 srcSize, result, (
int)targetSize);
1326 "LZ4_compress_HC_destSize() overwrites dst buffer");
1328 " (%i -> %i , expected > %i)",
srcSize, result, 1045000);
1342 FUZ_CHECKTEST(cSize==0,
"LZ4_compressHC_limitedOutput_continue() dictionary compression failed : @return = %i", cSize);
1348 FUZ_CHECKTEST(crc64!=crcNew,
"LZ4_decompress_safe() simple dictionary decompression test : corruption");
1353 {
int result1, result2;
1360 FUZ_CHECKTEST(result1==0,
"LZ4_compressHC_limitedOutput_continue() dictionary compression failed : result = %i", result1);
1362 result2 =
LZ4_compress_HC_continue(&sHC, testInput + 2*(
size_t)segSize, testCompressed+result1, segSize, segSize-1);
1363 FUZ_CHECKTEST(result2==0,
"LZ4_compressHC_limitedOutput_continue() dictionary compression failed : result = %i", result2);
1367 FUZ_CHECKTEST(result!=segSize,
"LZ4_decompress_safe() dictionary decompression part 1 failed");
1369 FUZ_CHECKTEST(result!=segSize,
"LZ4_decompress_safe() dictionary decompression part 2 failed");
1371 FUZ_CHECKTEST(crc64!=crcNew,
"LZ4_decompress_safe() dictionary decompression corruption");
1379 FUZ_CHECKTEST(result==0,
"LZ4_compressHC_limitedOutput_continue() remote dictionary failed : result = %i", result);
1383 FUZ_CHECKTEST(result!=(
int)
testCompressedSize,
"LZ4_decompress_safe_usingDict() decompression failed following remote dictionary HC compression test");
1385 FUZ_CHECKTEST(crc64!=crcNew,
"LZ4_decompress_safe_usingDict() decompression corruption");
1391 const char* dict = testInput + 3;
1392 size_t dictSize = (
FUZ_rand(&randState) & 8191);
1393 char*
dst = testVerify;
1395 size_t segStart = dictSize + 7;
1396 size_t segSize = (
FUZ_rand(&randState) & 8191);
1407 XXH64_update(&crcOrigState, testInput + segStart, segSize);
1411 FUZ_CHECKTEST(result==0,
"LZ4_compressHC_limitedOutput_continue() dictionary compression failed : result = %i", result);
1415 FUZ_CHECKTEST(result!=(
int)segSize,
"LZ4_decompress_safe_usingDict() dictionary decompression part %i failed", (
int)segNb);
1419 FUZ_CHECKTEST(crcOrig!=crcNew,
"LZ4_decompress_safe_usingDict() part %i corruption", segNb);
1428 segStart += segSize + (
FUZ_rand(&randState) & 0xF) + 1;
1429 segSize = (
FUZ_rand(&randState) & 8191);
1436 const U32 maxMessageSizeLog = 10;
1437 const U32 maxMessageSizeMask = (1<<maxMessageSizeLog) - 1;
1438 U32 messageSize = (
FUZ_rand(&randState) & maxMessageSizeMask) + 1;
1454 XXH64_update(&xxhOrig, testInput + iNext, messageSize);
1457 memcpy (ringBuffer + rNext, testInput + iNext, messageSize);
1465 FUZ_CHECKTEST(result!=(
int)messageSize,
"ringBuffer : LZ4_decompress_safe_continue() test failed");
1467 XXH64_update(&xxhNewSafe, testVerify + dNext, messageSize);
1469 FUZ_CHECKTEST(crcOrig!=crcNew,
"LZ4_decompress_safe_continue() decompression corruption"); }
1475 XXH64_update(&xxhNewFast, testVerify + dNext, messageSize);
1477 FUZ_CHECKTEST(crcOrig!=crcNew,
"LZ4_decompress_fast_continue() decompression corruption"); }
1480 iNext += messageSize;
1481 rNext += messageSize;
1482 dNext += messageSize;
1483 messageSize = (
FUZ_rand(&randState) & maxMessageSizeMask) + 1;
1485 if (dNext + messageSize > dBufferSize) dNext = 0;
1499 const int maxMessageSizeLog = 12;
1500 const int maxMessageSize = 1 << maxMessageSizeLog;
1501 const int maxMessageSizeMask = maxMessageSize - 1;
1503 U32 totalMessageSize = 0;
1505 char*
const ringBufferSafe = testVerify;
1506 char*
const ringBufferFast = testVerify + dBufferSize + 1;
1519 #define BSIZE1 (dBufferSize - (maxMessageSize-1))
1523 XXH64_update(&xxhOrig, testInput + iNext, (
size_t)messageSize);
1531 FUZ_CHECKTEST(result!=messageSize,
"64K D.ringBuffer : LZ4_decompress_safe_continue() test failed");
1533 XXH64_update(&xxhNewSafe, ringBufferSafe + dNext, (
size_t)messageSize);
1535 FUZ_CHECKTEST(crcOrig!=crcNew,
"LZ4_decompress_safe_continue() decompression corruption"); }
1540 XXH64_update(&xxhNewFast, ringBufferFast + dNext, (
size_t)messageSize);
1542 FUZ_CHECKTEST(crcOrig!=crcNew,
"LZ4_decompress_fast_continue() decompression corruption"); }
1545 dNext += messageSize;
1546 assert(messageSize >= 0);
1547 totalMessageSize += (
unsigned)messageSize;
1548 messageSize = maxMessageSize;
1551 memcpy(testInput + iNext, testInput + (
BSIZE1-65535), messageSize);
1552 FUZ_CHECKTEST(dNext+messageSize <= dBufferSize,
"Ring buffer test : second message should require restarting from beginning");
1555 while (totalMessageSize < 9
MB) {
1556 XXH64_update(&xxhOrig, testInput + iNext, (
size_t)messageSize);
1565 assert(dNext < dBufferSize);
1566 assert(dBufferSize - dNext >= maxMessageSize);
1568 testCompressed, ringBufferSafe + dNext,
1570 FUZ_CHECKTEST(result!=messageSize,
"D.ringBuffer : LZ4_decompress_safe_continue() test failed");
1571 XXH64_update(&xxhNewSafe, ringBufferSafe + dNext, (
size_t)messageSize);
1573 if (crcOrig != crcNew)
FUZ_findDiff(testInput + iNext, ringBufferSafe + dNext);
1574 FUZ_CHECKTEST(crcOrig!=crcNew,
"LZ4_decompress_safe_continue() decompression corruption during D.ringBuffer test");
1580 XXH64_update(&xxhNewFast, ringBufferFast + dNext, (
size_t)messageSize);
1582 if (crcOrig != crcNew)
FUZ_findDiff(testInput + iNext, ringBufferFast + dNext);
1583 FUZ_CHECKTEST(crcOrig!=crcNew,
"LZ4_decompress_fast_continue() decompression corruption during D.ringBuffer test");
1587 dNext += messageSize;
1588 assert(messageSize >= 0);
1589 totalMessageSize += (
unsigned)messageSize;
1590 messageSize = (
FUZ_rand(&randState) & maxMessageSizeMask) + 1;
1591 iNext = (
FUZ_rand(&randState) & 65535);
1592 if (dNext + maxMessageSize > dBufferSize) dNext = 0;
1600 int const src_buf_size = 3
MB;
1601 int const dst_buf_size = 6
KB;
1602 int const payload = 0;
1603 int const dst_step = 43;
1604 int const dst_min_len = 33 + (
FUZ_rand(&randState) % dst_step);
1605 int const dst_max_len = 5000;
1607 char* sbuf1 = (
char*)
malloc(src_buf_size + 1);
1608 char* sbuf2 = (
char*)
malloc(src_buf_size + 1);
1609 char* dbuf1 = (
char*)
malloc(dst_buf_size + 1);
1610 char* dbuf2 = (
char*)
malloc(dst_buf_size + 1);
1613 assert(dst_buf_size > dst_max_len);
1614 if (!sbuf1 || !sbuf2 || !dbuf1 || !dbuf2) {
1615 EXIT_MSG(
"not enough memory for FUZ_unitTests (destSize)");
1617 for (dlen = dst_min_len; dlen <= dst_max_len; dlen += dst_step) {
1618 int src_len = (dlen - 10)*255 + 24;
1619 if (src_len + 10 >= src_buf_size)
break;
1620 for (slen = src_len - 3; slen <= src_len + 3; slen++) {
1624 char const endchk = (char)0x88;
1628 memset(sbuf1, payload, slen);
1630 dbuf1[dlen] = endchk;
1632 DISPLAYLEVEL(5,
"LZ4_compress_destSize: %i bytes compressed into %i bytes, ", srcsz1, dsz1);
1633 DISPLAYLEVEL(5,
"last token : 0x%0X, ", dbuf1[dsz1 - 6]);
1634 DISPLAYLEVEL(5,
"last ML extra lenbyte : 0x%0X, \n", dbuf1[dsz1 - 7]);
1635 FUZ_CHECKTEST(dbuf1[dlen] != endchk,
"LZ4_compress_destSize() overwrite dst buffer !");
1636 FUZ_CHECKTEST(dsz1 <= 0,
"LZ4_compress_destSize() compression failed");
1637 FUZ_CHECKTEST(dsz1 > dlen,
"LZ4_compress_destSize() result larger than dst buffer !");
1638 FUZ_CHECKTEST(srcsz1 > slen,
"LZ4_compress_destSize() read more than src buffer !");
1641 FUZ_CHECKTEST(res1 != srcsz1,
"LZ4_compress_destSize() decompression failed!");
1644 memset(sbuf2, payload, slen);
1646 dbuf2[dlen] = endchk;
1649 DISPLAYLEVEL(5,
"LZ4_compress_HC_destSize: %i bytes compressed into %i bytes, ", srcsz2, dsz2);
1650 DISPLAYLEVEL(5,
"last token : 0x%0X, ", dbuf2[dsz2 - 6]);
1651 DISPLAYLEVEL(5,
"last ML extra lenbyte : 0x%0X, \n", dbuf2[dsz2 - 7]);
1652 FUZ_CHECKTEST(dbuf2[dlen] != endchk,
"LZ4_compress_HC_destSize() overwrite dst buffer !");
1653 FUZ_CHECKTEST(dsz2 <= 0,
"LZ4_compress_HC_destSize() compression failed");
1654 FUZ_CHECKTEST(dsz2 > dlen,
"LZ4_compress_HC_destSize() result larger than dst buffer !");
1655 FUZ_CHECKTEST(srcsz2 > slen,
"LZ4_compress_HC_destSize() read more than src buffer !");
1656 FUZ_CHECKTEST(dsz2 != dsz1,
"LZ4_compress_HC_destSize() return incorrect result !");
1657 FUZ_CHECKTEST(srcsz2 != srcsz1,
"LZ4_compress_HC_destSize() return incorrect src buffer size "
1658 ": srcsz2(%i) != srcsz1(%i)", srcsz2, srcsz1);
1659 FUZ_CHECKTEST(memcmp(dbuf2, dbuf1, (
size_t)dsz2),
"LZ4_compress_HC_destSize() return incorrect data into dst buffer !");
1662 FUZ_CHECKTEST(res2 != srcsz1,
"LZ4_compress_HC_destSize() decompression failed!");
1664 FUZ_CHECKTEST(memcmp(sbuf1, sbuf2, (
size_t)res2),
"LZ4_compress_HC_destSize() decompression corruption!");
1678 free(testCompressed);
1694 DISPLAY(
" %s [args]\n", programName);
1698 DISPLAY(
" -T# : Duration of tests, in seconds (default: use Nb of tests) \n");
1699 DISPLAY(
" -s# : Select seed (default:prompt user)\n");
1700 DISPLAY(
" -t# : Select starting test number (default:0)\n");
1703 DISPLAY(
" -p : pause at the end\n");
1704 DISPLAY(
" -h : display help and exit\n");
1715 unsigned testNb = 0;
1718 const char* programName =
argv[0];
1722 for(argNb=1; argNb<argc; argNb++) {
1723 const char* argument =
argv[argNb];
1725 if(!argument)
continue;
1728 if (argument[0]==
'-') {
1732 while (*argument!=0) {
1750 nbTests = 0; duration = 0;
1751 while ((*argument>=
'0') && (*argument<=
'9')) {
1753 nbTests += (
unsigned)(*argument -
'0');
1760 nbTests = 0; duration = 0;
1764 case 'm': duration *= 60; argument++;
continue;
1766 case 'n': argument++;
continue;
1776 case '9': duration *= 10; duration += (
U32)(*argument++ -
'0');
continue;
1785 while ((*argument>=
'0') && (*argument<=
'9')) {
1787 seed += (
U32)(*argument -
'0');
1795 while ((*argument>=
'0') && (*argument<=
'9')) {
1797 testNb += (
unsigned)(*argument -
'0');
1805 while ((*argument>=
'0') && (*argument<=
'9')) {
1807 proba += *argument -
'0';
1810 if (proba<0) proba=0;
1811 if (proba>100) proba=100;
1826 printf(
"Seed = %u\n", seed);
1832 nbTests += (nbTests==0);
1834 {
int const result =
FUZ_test(seed, nbTests, testNb, ((
double)proba) / 100, duration);
1836 DISPLAY(
"press enter ... \n");
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
LZ4_streamHC_t LZ4_streamHC
static LZ4_stream_t LZ4_stream
#define FUZ_MAX_DICT_SIZE
#define FUZ_CHECKTEST(cond,...)
int main(int argc, const char **argv)
static clock_t FUZ_GetClockSpan(clock_t clockStart)
#define COMPRESSIBLE_NOISE_LENGTH
#define FUZ_DISPLAYTEST(...)
static int FUZ_usage(const char *programName)
#define testCompressedSize
static U32 FUZ_rotl32(U32 u32, U32 nbBits)
static int FUZ_AddressOverflow(void)
static int FUZ_test(U32 seed, U32 nbCycles, const U32 startCycle, const double compressibility, U32 duration_s)
static void FUZ_fillCompressibleNoiseBuffer(void *buffer, size_t bufferSize, double proba, U32 *seed)
#define DISPLAYLEVEL(l,...)
static void FUZ_freeLowAddr(void *buffer, size_t size)
static void FUZ_unitTests(int compressionLevel)
#define FUZ_MAX_BLOCK_SIZE
#define FUZ_COMPRESSIBILITY_DEFAULT
static int g_displayLevel
static U32 FUZ_highbit32(U32 v32)
static void FUZ_findDiff(const void *buff1, const void *buff2)
static U32 FUZ_rand(U32 *src)
static void * FUZ_createLowAddr(size_t size)
static void FUZ_displayUpdate(unsigned testNb)
unsigned char match[65280+2]
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
static static fork const void static count static fd const char const char static newpath char char char static envp time
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags mmap
static static fork const void static count static fd const char const char static newpath char char argv
static const void static count static fd struct stat static buf struct pollfd unsigned static timeout void static offset munmap
static void struct sockaddr socklen_t static fromlen static backlog static fork char char char static envp int struct rusage static rusage struct utsname static buf struct sembuf unsigned
XXH_PUBLIC_API unsigned int XXH32(const void *input, size_t len, unsigned int seed)
XXH_PUBLIC_API XXH_errorcode XXH64_update(XXH64_state_t *state_in, const void *input, size_t len)
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, unsigned long long seed)
XXH_PUBLIC_API unsigned long long XXH64(const void *input, size_t len, unsigned long long seed)
XXH_PUBLIC_API unsigned long long XXH64_digest(const XXH64_state_t *state_in)
struct XXH64_state_s XXH64_state_t
unsigned long long XXH64_hash_t
unsigned int XXH32_hash_t
int LZ4_compress_fast_extState(void *state, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
int LZ4_decompress_fast_usingDict(const char *source, char *dest, int originalSize, const char *dictStart, int dictSize)
const char * LZ4_versionString(void)
int LZ4_compressBound(int isize)
int LZ4_loadDict(LZ4_stream_t *LZ4_dict, const char *dictionary, int dictSize)
LZ4_stream_t * LZ4_createStream(void)
int LZ4_decompress_safe_usingDict(const char *source, char *dest, int compressedSize, int maxOutputSize, const char *dictStart, int dictSize)
LZ4_stream_t * LZ4_initStream(void *buffer, size_t size)
int LZ4_decoderRingBufferSize(int maxBlockSize)
int LZ4_compress_default(const char *src, char *dst, int srcSize, int maxOutputSize)
int LZ4_compress_destSize(const char *src, char *dst, int *srcSizePtr, int targetDstSize)
int LZ4_sizeofState(void)
LZ4_FORCE_O2 int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *source, char *dest, int originalSize)
void LZ4_resetStream_fast(LZ4_stream_t *ctx)
int LZ4_freeStream(LZ4_stream_t *LZ4_stream)
int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode, const char *dictionary, int dictSize)
LZ4_FORCE_O2 int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *source, char *dest, int compressedSize, int maxOutputSize)
LZ4_FORCE_O2 int LZ4_decompress_fast(const char *source, char *dest, int originalSize)
LZ4_FORCE_O2 int LZ4_decompress_safe_partial(const char *src, char *dst, int compressedSize, int targetOutputSize, int dstCapacity)
int LZ4_saveDict(LZ4_stream_t *LZ4_dict, char *safeBuffer, int dictSize)
int LZ4_compress_fast_continue(LZ4_stream_t *LZ4_stream, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
int LZ4_compress_fast_extState_fastReset(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
void LZ4_attach_dictionary(LZ4_stream_t *workingStream, const LZ4_stream_t *dictionaryStream)
LZ4_FORCE_O2 int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)
#define LZ4_COMPRESSBOUND(isize)
int LZ4_compress_HC_extStateHC(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
void LZ4_attach_HC_dictionary(LZ4_streamHC_t *working_stream, const LZ4_streamHC_t *dictionary_stream)
void LZ4_resetStreamHC_fast(LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel)
int LZ4_saveDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, char *safeBuffer, int dictSize)
LZ4_streamHC_t * LZ4_initStreamHC(void *buffer, size_t size)
int LZ4_freeHC(void *LZ4HC_Data)
int LZ4_sizeofStateHC(void)
int LZ4_compress_HC_continue_destSize(LZ4_streamHC_t *LZ4_streamHCPtr, const char *src, char *dst, int *srcSizePtr, int targetDestSize)
void * LZ4_createHC(const char *inputBuffer)
int LZ4_compress_HC_destSize(void *state, const char *source, char *dest, int *sourceSizePtr, int targetDestSize, int cLevel)
int LZ4_freeStreamHC(LZ4_streamHC_t *LZ4_streamHCPtr)
int LZ4_compress_HC_continue(LZ4_streamHC_t *LZ4_streamHCPtr, const char *src, char *dst, int srcSize, int dstCapacity)
int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
LZ4_streamHC_t * LZ4_createStreamHC(void)
int LZ4_compress_HC_extStateHC_fastReset(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
void LZ4_setCompressionLevel(LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel)
int LZ4_loadDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, const char *dictionary, int dictSize)
void LZ4_resetStreamHC(LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel)
#define LZ4HC_CLEVEL_OPT_MIN
#define LZ4HC_CLEVEL_DEFAULT
char int int compressionLevel
assert(limit<=UINT32_MAX/2)
_W64 unsigned int uintptr_t
LZ4HC_CCtx_internal internal_donotuse
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)