mirror of
https://github.com/facebook/zstd.git
synced 2025-07-29 11:21:22 +03:00
Merge pull request #2375 from senhuang42/ldm_oss_fuzz_testcase
Add a test case for LDM + opt parser with small uncompressible block
This commit is contained in:
@ -717,6 +717,48 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
||||
}
|
||||
DISPLAYLEVEL(3, "OK \n");
|
||||
|
||||
DISPLAYLEVEL(3, "test%3i : LDM + opt parser with small uncompressible block ", testNb++);
|
||||
{ ZSTD_CCtx* cctx = ZSTD_createCCtx();
|
||||
ZSTD_DCtx* dctx = ZSTD_createDCtx();
|
||||
size_t const srcSize = 300 KB;
|
||||
size_t const flushSize = 128 KB + 5;
|
||||
size_t const dstSize = ZSTD_compressBound(srcSize);
|
||||
char* src = (char*)CNBuffer;
|
||||
char* dst = (char*)compressedBuffer;
|
||||
|
||||
ZSTD_outBuffer out = { dst, dstSize, 0 };
|
||||
ZSTD_inBuffer in = { src, flushSize, 0 };
|
||||
|
||||
if (!cctx || !dctx) {
|
||||
DISPLAY("Not enough memory, aborting\n");
|
||||
testResult = 1;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
RDG_genBuffer(src, srcSize, 0.5, 0.5, seed);
|
||||
/* Force an LDM to exist that crosses block boundary into uncompressible block */
|
||||
memcpy(src + 125 KB, src, 3 KB + 5);
|
||||
|
||||
/* Enable MT, LDM, and opt parser */
|
||||
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, 1));
|
||||
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_enableLongDistanceMatching, 1));
|
||||
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1));
|
||||
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, 19));
|
||||
|
||||
/* Flushes a block of 128 KB and block of 5 bytes */
|
||||
CHECK_Z(ZSTD_compressStream2(cctx, &out, &in, ZSTD_e_flush));
|
||||
|
||||
/* Compress the rest */
|
||||
in.size = 300 KB;
|
||||
CHECK_Z(ZSTD_compressStream2(cctx, &out, &in, ZSTD_e_end));
|
||||
|
||||
CHECK_Z(ZSTD_decompress(decodedBuffer, CNBuffSize, dst, out.pos));
|
||||
|
||||
ZSTD_freeCCtx(cctx);
|
||||
ZSTD_freeDCtx(dctx);
|
||||
}
|
||||
DISPLAYLEVEL(3, "OK \n");
|
||||
|
||||
DISPLAYLEVEL(3, "test%3i : testing ldm dictionary gets invalidated : ", testNb++);
|
||||
{
|
||||
ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
||||
|
Reference in New Issue
Block a user