Lines Matching +full:make +full:- +full:external +full:- +full:compressors
2 fuzzer.c - Fuzzer test tool for LZ4
3 Copyright (C) Yann Collet 2012-2020
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 - LZ4 homepage : http://www.lz4.org
23 - LZ4 source repo : https://github.com/lz4/lz4
26 /*-************************************
37 /*-************************************
42 # define _GNU_SOURCE /* MAP_ANONYMOUS even in -std=c99 mode */
67 /*-************************************
71 typedef size_t uintptr_t; /* true on most systems, except OpenVMS-64 (which doesn't need address …
75 /*-************************************
92 /*-***************************************
102 /*-*******************************************************
107 return clock() - clockStart; /* works even if overflow; max span ~ 30mn */ in FUZ_GetClockSpan()
123 return ((u32 << nbBits) | (u32 >> (32 - nbBits))); in FUZ_rotl32()
166 match = pos - offset; in FUZ_fillCompressibleNoiseBuffer()
183 * only possible in 32-bits mode */
192 /* Only possible in 32-bits */ in FUZ_AddressOverflow()
218 { size_t const sizeToGenerateOverflow = (size_t)(- ((uintptr_t)buffers[nbBuff-1]) + 512); in FUZ_AddressOverflow()
220 char* const input = buffers[nbBuff-1]; in FUZ_AddressOverflow()
237 output = buffers[nbBuff-2]; /* Reverse in/out pointer order */ in FUZ_AddressOverflow()
272 -1, 0); in FUZ_createLowAddr()
350 printf("\r%4u - %2u :", cycleNb, testNb); \ in FUZ_test()
377 int const blockSize = (FUZ_rand(&randState) % (FUZ_MAX_BLOCK_SIZE-1)) + 1; in FUZ_test()
378 …st blockStart = (int)(FUZ_rand(&randState) % (U32)(COMPRESSIBLE_NOISE_LENGTH - blockSize - 1)) + 1; in FUZ_test()
380 int const dictSize = MIN(dictSizeRand, blockStart - 1); in FUZ_test()
383 const char* dict = block - dictSize; in FUZ_test()
465 /* Test compression HC using external state */ in FUZ_test()
471 /* Test compression HC using fast reset external state */ in FUZ_test()
477 /* Test compression using external state */ in FUZ_test()
482 /* Test compression using fast reset external state*/ in FUZ_test()
518 FUZ_DISPLAYTEST("LZ4_decompress_fast() with output buffer 1-byte too short"); in FUZ_test()
519 decodedBuffer[blockSize-1] = 0; in FUZ_test()
520 { int const r = LZ4_decompress_fast(cBuffer_exact, decodedBuffer, blockSize-1); in FUZ_test()
523 …FUZ_CHECKTEST(decodedBuffer[blockSize-1]!=0, "LZ4_decompress_fast overrun specified output buffer"… in FUZ_test()
558 decodedBuffer[blockSize-1] = 0; in FUZ_test()
559 … { int const r = LZ4_decompress_safe(cBuffer_exact, decodedBuffer, compressedSize, blockSize-1); in FUZ_test()
562 …FUZ_CHECKTEST(decodedBuffer[blockSize-1], "LZ4_decompress_safe overrun specified output buffer siz… in FUZ_test()
567 decodedBuffer[blockSize-10] = 0; in FUZ_test()
568 … { int const r = LZ4_decompress_safe(cBuffer_exact, decodedBuffer, compressedSize, blockSize-10); in FUZ_test()
571 …FUZ_CHECKTEST(decodedBuffer[blockSize-10], "LZ4_decompress_safe overrun specified output buffer si… in FUZ_test()
582 size_t const mask = (1ULL <<nbBits) - 1; in FUZ_test()
589 U32 const nbBits = nbBitsCodes ? nbBitsCodes-1 : 0; in FUZ_test()
590 size_t const mask = (1ULL <<nbBits) - 1; in FUZ_test()
592 size_t const noiseLength = MIN(rNoiseLength, (size_t)compressedSize-pos); in FUZ_test()
593 … size_t const noiseStart = FUZ_rand(&randState) % (COMPRESSIBLE_NOISE_LENGTH - noiseLength); in FUZ_test()
615 …{ int const r = LZ4_decompress_safe(compressedBuffer, decodedBuffer, compressedSize-1, blockSize… in FUZ_test()
630 int const targetSize = (int)((size_t)blockSize - missingOutBytes); in FUZ_test()
644 int const targetSize = (int)((size_t)blockSize - missingOutBytes); in FUZ_test()
657 int const targetSize = (int)((size_t)blockSize - missingOutBytes); in FUZ_test()
668 FUZ_DISPLAYTEST("test LZ4_decompress_safe_partial_usingDict() using external dict"); in FUZ_test()
670 int const targetSize = (int)((size_t)blockSize - missingOutBytes); in FUZ_test()
688 …/* Test compression with output size being exactly what's necessary and external state (should wor… in FUZ_test()
706 if (missingBytes >= compressedSize) missingBytes = compressedSize-1; in FUZ_test()
708 compressedBuffer[compressedSize-missingBytes] = 0; in FUZ_test()
709 …onst cSize = LZ4_compress_default(block, compressedBuffer, blockSize, compressedSize-missingBytes); in FUZ_test()
712 …FUZ_CHECKTEST(compressedBuffer[compressedSize-missingBytes], "LZ4_compress_default overran output … in FUZ_test()
718 if (missingBytes >= HCcompressedSize) missingBytes = HCcompressedSize-1; in FUZ_test()
720 compressedBuffer[HCcompressedSize-missingBytes] = 0; in FUZ_test()
721 …cSize = LZ4_compress_HC(block, compressedBuffer, blockSize, HCcompressedSize-missingBytes, compres… in FUZ_test()
724 …FUZ_CHECKTEST(compressedBuffer[HCcompressedSize-missingBytes], "LZ4_compress_HC overran output buf… in FUZ_test()
728 /*-******************/ in FUZ_test()
730 /*-******************/ in FUZ_test()
759 /* Compress using External dictionary */ in FUZ_test()
760 FUZ_DISPLAYTEST("test LZ4_compress_fast_continue(), with non-contiguous dictionary"); in FUZ_test()
761 …dict -= (size_t)(FUZ_rand(&randState) & 0xF) + 1; /* create space, so now dictionary is an ExtDi… in FUZ_test()
769 …_fast_continue(&LZ4dictBody, block, compressedBuffer, blockSize, blockContinueCompressedSize-1, 1); in FUZ_test()
780 /* Decompress with dictionary as external */ in FUZ_test()
804 decodedBuffer[blockSize-1] = 0; in FUZ_test()
805 … ret = LZ4_decompress_fast_usingDict(compressedBuffer, decodedBuffer, blockSize-1, dict, dictSize); in FUZ_test()
806 …CKTEST(ret>=0, "LZ4_decompress_fast_usingDict should have failed : wrong original size (-1 byte)"); in FUZ_test()
807 …FUZ_CHECKTEST(decodedBuffer[blockSize-1], "LZ4_decompress_fast_usingDict overrun specified output … in FUZ_test()
810 decodedBuffer[blockSize-1] = 0; in FUZ_test()
811 …ingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize-1, dict, dictSize); in FUZ_test()
812 …EST(ret>=0, "LZ4_decompress_safe_usingDict should have failed : not enough output size (-1 byte)"); in FUZ_test()
813 …FUZ_CHECKTEST(decodedBuffer[blockSize-1], "LZ4_decompress_safe_usingDict overrun specified output … in FUZ_test()
818 decodedBuffer[blockSize-missingBytes] = 0; in FUZ_test()
819 …Dict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize-missingBytes, dict, d… in FUZ_test()
820 …LZ4_decompress_safe_usingDict should have failed : output buffer too small (-%i byte)", missingByt… in FUZ_test()
821 …CHECKTEST(decodedBuffer[blockSize-missingBytes], "LZ4_decompress_safe_usingDict overrun specified … in FUZ_test()
824 /* Compress using external dictionary stream */ in FUZ_test()
847 …xpectedSize, "LZ4_compress_fast_continue using extDictCtx produced different-sized output (%d expe… in FUZ_test()
853 …s_fast_continue(&LZ4_stream, block, compressedBuffer, blockSize, blockContinueCompressedSize-1, 1); in FUZ_test()
863 …et != expectedSize, "LZ4_compress_fast_continue using extDictCtx produced different-sized output"); in FUZ_test()
871 …FUZ_CHECKTEST(ret<=0, "LZ4_compress_fast_continue using extDictCtx with re-used context should wor… in FUZ_test()
872 …et != expectedSize, "LZ4_compress_fast_continue using extDictCtx produced different-sized output"); in FUZ_test()
876 /* Decompress with dictionary as external */ in FUZ_test()
898 decodedBuffer[blockSize-1] = 0; in FUZ_test()
899 … ret = LZ4_decompress_fast_usingDict(compressedBuffer, decodedBuffer, blockSize-1, dict, dictSize); in FUZ_test()
900 …CKTEST(ret>=0, "LZ4_decompress_fast_usingDict should have failed : wrong original size (-1 byte)"); in FUZ_test()
901 …FUZ_CHECKTEST(decodedBuffer[blockSize-1], "LZ4_decompress_fast_usingDict overrun specified output … in FUZ_test()
904 decodedBuffer[blockSize-1] = 0; in FUZ_test()
905 …ingDict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize-1, dict, dictSize); in FUZ_test()
906 …EST(ret>=0, "LZ4_decompress_safe_usingDict should have failed : not enough output size (-1 byte)"); in FUZ_test()
907 …FUZ_CHECKTEST(decodedBuffer[blockSize-1], "LZ4_decompress_safe_usingDict overrun specified output … in FUZ_test()
912 decodedBuffer[blockSize-missingBytes] = 0; in FUZ_test()
913 …Dict(compressedBuffer, decodedBuffer, blockContinueCompressedSize, blockSize-missingBytes, dict, d… in FUZ_test()
914 …LZ4_decompress_safe_usingDict should have failed : output buffer too small (-%i byte)", missingByt… in FUZ_test()
915 …CHECKTEST(decodedBuffer[blockSize-missingBytes], "LZ4_decompress_safe_usingDict overrun specified … in FUZ_test()
918 /* Compress HC using External dictionary */ in FUZ_test()
919 FUZ_DISPLAYTEST("LZ4_compress_HC_continue with an external dictionary"); in FUZ_test()
920 dict -= (FUZ_rand(&randState) & 7); /* even bigger separation */ in FUZ_test()
926 FUZ_CHECKTEST(LZ4dictHC->internal_donotuse.dirty, "Context should be clean"); in FUZ_test()
928 …FUZ_DISPLAYTEST("LZ4_compress_HC_continue with same external dictionary, but output buffer 1 byte … in FUZ_test()
930 …compress_HC_continue(LZ4dictHC, block, compressedBuffer, blockSize, blockContinueCompressedSize-1); in FUZ_test()
934 …FUZ_DISPLAYTEST("LZ4_compress_HC_continue with same external dictionary, and output buffer exactly… in FUZ_test()
939 FUZ_CHECKTEST(LZ4dictHC->internal_donotuse.dirty, "Context should be clean"); in FUZ_test()
952 /* Compress HC using external dictionary stream */ in FUZ_test()
961 FUZ_CHECKTEST(LZ4_streamHC->internal_donotuse.dirty, "Context should be clean"); in FUZ_test()
966 …press_HC_continue(LZ4_streamHC, block, compressedBuffer, blockSize, blockContinueCompressedSize-1); in FUZ_test()
976 FUZ_CHECKTEST(LZ4_streamHC->internal_donotuse.dirty, "Context should be clean"); in FUZ_test()
985 FUZ_CHECKTEST(LZ4_streamHC->internal_donotuse.dirty, "Context should be clean"); in FUZ_test()
1042 printf("\r%7u /%7u - ", cycleNb, nbCycles); in FUZ_test()
1081 /* 32-bits address space overflow test */ in FUZ_unitTests()
1128 /* in-place compression test */ in FUZ_unitTests()
1129 DISPLAYLEVEL(3, "in-place compression using LZ4_compress_default() :"); in FUZ_unitTests()
1133 int const startInputIndex = outSize - sampleSize; in FUZ_unitTests()
1139 /* compress in-place */ in FUZ_unitTests()
1152 /* in-place decompression test */ in FUZ_unitTests()
1153 DISPLAYLEVEL(3, "in-place decompression, limit case:"); in FUZ_unitTests()
1157 … memset(testInput, 0, 267); /* calculated exactly so that compressedSize == originalSize-1 */ in FUZ_unitTests()
1161 assert(cSize == sampleSize - 1); /* worst case for in-place decompression */ in FUZ_unitTests()
1164 int const startInputIndex = bufferSize - cSize; in FUZ_unitTests()
1187 …(void*)&(shc->state1), (void*)&(shc->state2), (void*)&(shc->state3), (unsigned)sizeof(LZ4_stream_t… in FUZ_unitTests()
1188 …FUZ_CHECKTEST( LZ4_initStream(&(shc->state1), sizeof(shc->state1)) == NULL, "state1 (%p) failed in… in FUZ_unitTests()
1189 …FUZ_CHECKTEST( LZ4_initStream(&(shc->state2), sizeof(shc->state2)) == NULL, "state2 (%p) failed in… in FUZ_unitTests()
1190 …FUZ_CHECKTEST( LZ4_initStream(&(shc->state3), sizeof(shc->state3)) == NULL, "state3 (%p) failed in… in FUZ_unitTests()
1191 FUZ_CHECKTEST( LZ4_initStream((char*)&(shc->state1) + 1, sizeof(shc->state1)) != NULL, in FUZ_unitTests()
1192 … "hc1+1 (%p) init must fail, due to bad alignment", (void*)((char*)&(shc->state1) + 1) ); in FUZ_unitTests()
1208 …_continue(&streamingState, testInput, testCompressed, testCompressedSize, testCompressedSize-1, 1); in FUZ_unitTests()
1239 const U32 maxMessageSizeMask = (1<<maxMessageSizeLog) - 1; in FUZ_unitTests()
1259 …State, ringBuffer + rNext, testCompressed, (int)messageSize, testCompressedSize-ringBufferSize, 1); in FUZ_unitTests()
1297 (void*)&(shc->hc1), (void*)&(shc->hc2), (void*)&(shc->hc3), in FUZ_unitTests()
1299 …FUZ_CHECKTEST( LZ4_initStreamHC(&(shc->hc1), sizeof(shc->hc1)) == NULL, "hc1 (%p) failed init", (v… in FUZ_unitTests()
1300 …FUZ_CHECKTEST( LZ4_initStreamHC(&(shc->hc2), sizeof(shc->hc2)) == NULL, "hc2 (%p) failed init", (v… in FUZ_unitTests()
1301 …FUZ_CHECKTEST( LZ4_initStreamHC(&(shc->hc3), sizeof(shc->hc3)) == NULL, "hc3 (%p) failed init", (v… in FUZ_unitTests()
1302 FUZ_CHECKTEST( LZ4_initStreamHC((char*)&(shc->hc1) + 1, sizeof(shc->hc1)) != NULL, in FUZ_unitTests()
1303 … "hc1+1 (%p) init must fail, due to bad alignment", (void*)((char*)&(shc->hc1) + 1) ); in FUZ_unitTests()
1322 DISPLAYLEVEL(3, "Simple HC round-trip : "); in FUZ_unitTests()
1325 …Z4_compress_HC_continue(&sHC, testInput, testCompressed, testCompressedSize, testCompressedSize-1); in FUZ_unitTests()
1372 "compression (%i->%i) must fill dstBuffer (%i) exactly", in FUZ_unitTests()
1377 " (%i -> %i , expected > %i)", srcSize, result, 1045000); in FUZ_unitTests()
1379 LZ4_resetStreamHC_fast(&sHC, 3); /* make sure the context is clean after the test */ in FUZ_unitTests()
1390 …ess_HC_continue(&sHC, testInput + 64 KB, testCompressed, testCompressedSize, testCompressedSize-1); in FUZ_unitTests()
1408 …result1 = LZ4_compress_HC_continue(&sHC, testInput + segSize, testCompressed, segSize, segSize -1); in FUZ_unitTests()
1411 …press_HC_continue(&sHC, testInput + 2*(size_t)segSize, testCompressed+result1, segSize, segSize-1); in FUZ_unitTests()
1427 …ess_HC_continue(&sHC, testInput + 64 KB, testCompressed, testCompressedSize, testCompressedSize-1); in FUZ_unitTests()
1486 const U32 maxMessageSizeMask = (1<<maxMessageSizeLog) - 1; in FUZ_unitTests()
1508 …nue(&sHC, ringBuffer + rNext, testCompressed, (int)messageSize, testCompressedSize-ringBufferSize); in FUZ_unitTests()
1550 const int maxMessageSizeMask = maxMessageSize - 1; in FUZ_unitTests()
1568 #define BSIZE1 (dBufferSize - (maxMessageSize-1)) in FUZ_unitTests()
1575 …_continue(&sHC, testInput + iNext, testCompressed, messageSize, testCompressedSize-ringBufferSize); in FUZ_unitTests()
1600 …memcpy(testInput + iNext, testInput + (BSIZE1-65535), messageSize); /* will generate a match at m… in FUZ_unitTests()
1608 …_continue(&sHC, testInput + iNext, testCompressed, messageSize, testCompressedSize-ringBufferSize); in FUZ_unitTests()
1615 assert(dBufferSize - dNext >= maxMessageSize); in FUZ_unitTests()
1618 …compressedSize, dBufferSize - dNext); /* works without knowing messageSize, under assumption tha… in FUZ_unitTests()
1647 /* encode congenerical sequence test for HC compressors */ in FUZ_unitTests()
1667 int src_len = (dlen - 10)*255 + 24; in FUZ_unitTests()
1669 for (slen = src_len - 3; slen <= src_len + 3; slen++) { in FUZ_unitTests()
1682 DISPLAYLEVEL(5, "last token : 0x%0X, ", dbuf1[dsz1 - 6]); in FUZ_unitTests()
1683 DISPLAYLEVEL(5, "last ML extra lenbyte : 0x%0X, \n", dbuf1[dsz1 - 7]); in FUZ_unitTests()
1699 DISPLAYLEVEL(5, "last token : 0x%0X, ", dbuf2[dsz2 - 6]); in FUZ_unitTests()
1700 DISPLAYLEVEL(5, "last ML extra lenbyte : 0x%0X, \n", dbuf2[dsz2 - 7]); in FUZ_unitTests()
1746 DISPLAY( " -i# : Nb of tests (default:%i) \n", NB_ATTEMPTS); in FUZ_usage()
1747 DISPLAY( " -T# : Duration of tests, in seconds (default: use Nb of tests) \n"); in FUZ_usage()
1748 DISPLAY( " -s# : Select seed (default:prompt user)\n"); in FUZ_usage()
1749 DISPLAY( " -t# : Select starting test number (default:0)\n"); in FUZ_usage()
1750 … DISPLAY( " -P# : Select compressibility in %% (default:%i%%)\n", FUZ_COMPRESSIBILITY_DEFAULT); in FUZ_usage()
1751 DISPLAY( " -v : verbose\n"); in FUZ_usage()
1752 DISPLAY( " -p : pause at the end\n"); in FUZ_usage()
1753 DISPLAY( " -h : display help and exit\n"); in FUZ_usage()
1777 if (argument[0]=='-') { in main()
1778 … if (!strcmp(argument, "--no-prompt")) { use_pause=0; seedset=1; g_displayLevel=1; continue; } in main()
1802 nbTests += (unsigned)(*argument - '0'); in main()
1825 … case '9': duration *= 10; duration += (U32)(*argument++ - '0'); continue; in main()
1836 seed += (U32)(*argument - '0'); in main()
1846 testNb += (unsigned)(*argument - '0'); in main()
1856 proba += *argument - '0'; in main()
1868 printf("Starting LZ4 fuzzer (%i-bits, v%s)\n", (int)(sizeof(size_t)*8), LZ4_versionString()); in main()