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);
LZ4_streamHC_t LZ4_streamHC
static LZ4_stream_t LZ4_stream
#define FUZ_MAX_DICT_SIZE
#define FUZ_CHECKTEST(cond,...)
#define COMPRESSIBLE_NOISE_LENGTH
#define FUZ_DISPLAYTEST(...)
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)
#define FUZ_MAX_BLOCK_SIZE
static U32 FUZ_highbit32(U32 v32)
static void FUZ_findDiff(const void *buff1, const void *buff2)
static void * FUZ_createLowAddr(size_t size)
static void FUZ_displayUpdate(unsigned testNb)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
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)
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)
int LZ4_compressBound(int isize)
int LZ4_loadDict(LZ4_stream_t *LZ4_dict, const char *dictionary, int dictSize)
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_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)
void LZ4_resetStream_fast(LZ4_stream_t *ctx)
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_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)
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_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)
char int int compressionLevel
assert(limit<=UINT32_MAX/2)
LZ4HC_CCtx_internal internal_donotuse