fixed bug #73 notified by @nemequ
This commit is contained in:
parent
dcac00e7a6
commit
110cc14bab
@ -1219,7 +1219,7 @@ FORCE_INLINE size_t ZSTD_HcFindBestMatch_selectMLS (
|
|||||||
FORCE_INLINE
|
FORCE_INLINE
|
||||||
size_t ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx,
|
size_t ZSTD_compressBlock_lazy_generic(ZSTD_CCtx* ctx,
|
||||||
void* dst, size_t maxDstSize, const void* src, size_t srcSize,
|
void* dst, size_t maxDstSize, const void* src, size_t srcSize,
|
||||||
const U32 searchMethod, const U32 deep) /* 0 : hc; 1 : bt */
|
const U32 searchMethod, const U32 deep) /* searchMethod : 0 = hc; 1 = bt */
|
||||||
{
|
{
|
||||||
seqStore_t* seqStorePtr = &(ctx->seqStore);
|
seqStore_t* seqStorePtr = &(ctx->seqStore);
|
||||||
const BYTE* const istart = (const BYTE*)src;
|
const BYTE* const istart = (const BYTE*)src;
|
||||||
@ -1496,6 +1496,7 @@ static ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, int
|
|||||||
size_t ZSTD_compressBlock(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
size_t ZSTD_compressBlock(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
ZSTD_blockCompressor blockCompressor = ZSTD_selectBlockCompressor(ctx->params.strategy, ctx->lowLimit < ctx->dictLimit);
|
ZSTD_blockCompressor blockCompressor = ZSTD_selectBlockCompressor(ctx->params.strategy, ctx->lowLimit < ctx->dictLimit);
|
||||||
|
if (srcSize < MIN_CBLOCK_SIZE+3) return 0; /* don't even attempt compression below a certain srcSize */
|
||||||
return blockCompressor(ctx, dst, maxDstSize, src, srcSize);
|
return blockCompressor(ctx, dst, maxDstSize, src, srcSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
#define MB *(1U<<20)
|
#define MB *(1U<<20)
|
||||||
#define GB *(1U<<30)
|
#define GB *(1U<<30)
|
||||||
|
|
||||||
static const U32 nbTestsDefault = 32 KB;
|
static const U32 nbTestsDefault = 30000;
|
||||||
#define COMPRESSIBLE_NOISE_LENGTH (10 MB)
|
#define COMPRESSIBLE_NOISE_LENGTH (10 MB)
|
||||||
#define FUZ_COMPRESSIBILITY_DEFAULT 50
|
#define FUZ_COMPRESSIBILITY_DEFAULT 50
|
||||||
static const U32 prime1 = 2654435761U;
|
static const U32 prime1 = 2654435761U;
|
||||||
@ -89,6 +89,8 @@ static U32 g_time = 0;
|
|||||||
/*********************************************************
|
/*********************************************************
|
||||||
* Fuzzer functions
|
* Fuzzer functions
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
|
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||||
|
|
||||||
static U32 FUZ_GetMilliStart(void)
|
static U32 FUZ_GetMilliStart(void)
|
||||||
{
|
{
|
||||||
struct timeb tb;
|
struct timeb tb;
|
||||||
@ -299,6 +301,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
|
|||||||
U32 sampleSizeLog, buffNb, cLevelMod;
|
U32 sampleSizeLog, buffNb, cLevelMod;
|
||||||
U64 crcOrig, crcDest;
|
U64 crcOrig, crcDest;
|
||||||
int cLevel;
|
int cLevel;
|
||||||
|
BYTE* sampleBuffer;
|
||||||
|
|
||||||
/* init */
|
/* init */
|
||||||
DISPLAYUPDATE(2, "\r%6u/%6u ", testNb, nbTests);
|
DISPLAYUPDATE(2, "\r%6u/%6u ", testNb, nbTests);
|
||||||
@ -325,13 +328,17 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
|
|||||||
sampleSize = (size_t)1 << sampleSizeLog;
|
sampleSize = (size_t)1 << sampleSizeLog;
|
||||||
sampleSize += FUZ_rand(&lseed) & (sampleSize-1);
|
sampleSize += FUZ_rand(&lseed) & (sampleSize-1);
|
||||||
sampleStart = FUZ_rand(&lseed) % (srcBufferSize - sampleSize);
|
sampleStart = FUZ_rand(&lseed) % (srcBufferSize - sampleSize);
|
||||||
crcOrig = XXH64(srcBuffer + sampleStart, sampleSize, 0);
|
|
||||||
|
|
||||||
/* HC compression test */
|
/* create sample buffer (to catch read error with valgrind & sanitizers) */
|
||||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
sampleBuffer = (BYTE*)malloc(sampleSize);
|
||||||
|
CHECK (sampleBuffer==NULL, "not enough memory for sample buffer");
|
||||||
|
memcpy(sampleBuffer, srcBuffer + sampleStart, sampleSize);
|
||||||
|
crcOrig = XXH64(sampleBuffer, sampleSize, 0);
|
||||||
|
|
||||||
|
/* compression test */
|
||||||
cLevelMod = MAX(1, 38 - (int)(MAX(9, sampleSizeLog) * 2)); /* use high compression levels with small samples, for speed */
|
cLevelMod = MAX(1, 38 - (int)(MAX(9, sampleSizeLog) * 2)); /* use high compression levels with small samples, for speed */
|
||||||
cLevel = (FUZ_rand(&lseed) % cLevelMod) +1;
|
cLevel = (FUZ_rand(&lseed) % cLevelMod) +1;
|
||||||
cSize = ZSTD_compressCCtx(hcctx, cBuffer, cBufferSize, srcBuffer + sampleStart, sampleSize, cLevel);
|
cSize = ZSTD_compressCCtx(hcctx, cBuffer, cBufferSize, sampleBuffer, sampleSize, cLevel);
|
||||||
CHECK(ZSTD_isError(cSize), "ZSTD_compressCCtx failed");
|
CHECK(ZSTD_isError(cSize), "ZSTD_compressCCtx failed");
|
||||||
|
|
||||||
/* compression failure test : too small dest buffer */
|
/* compression failure test : too small dest buffer */
|
||||||
@ -343,7 +350,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
|
|||||||
static const U32 endMark = 0x4DC2B1A9;
|
static const U32 endMark = 0x4DC2B1A9;
|
||||||
U32 endCheck;
|
U32 endCheck;
|
||||||
memcpy(dstBuffer+tooSmallSize, &endMark, 4);
|
memcpy(dstBuffer+tooSmallSize, &endMark, 4);
|
||||||
errorCode = ZSTD_compressCCtx(hcctx, dstBuffer, tooSmallSize, srcBuffer + sampleStart, sampleSize, cLevel);
|
errorCode = ZSTD_compressCCtx(hcctx, dstBuffer, tooSmallSize, sampleBuffer, sampleSize, cLevel);
|
||||||
CHECK(!ZSTD_isError(errorCode), "ZSTD_compressCCtx should have failed ! (buffer too small : %u < %u)", (U32)tooSmallSize, (U32)cSize);
|
CHECK(!ZSTD_isError(errorCode), "ZSTD_compressCCtx should have failed ! (buffer too small : %u < %u)", (U32)tooSmallSize, (U32)cSize);
|
||||||
memcpy(&endCheck, dstBuffer+tooSmallSize, 4);
|
memcpy(&endCheck, dstBuffer+tooSmallSize, 4);
|
||||||
CHECK(endCheck != endMark, "ZSTD_compressCCtx : dst buffer overflow");
|
CHECK(endCheck != endMark, "ZSTD_compressCCtx : dst buffer overflow");
|
||||||
@ -354,7 +361,9 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
|
|||||||
dSize = ZSTD_decompress(dstBuffer, sampleSize + dSupSize, cBuffer, cSize);
|
dSize = ZSTD_decompress(dstBuffer, sampleSize + dSupSize, cBuffer, cSize);
|
||||||
CHECK(dSize != sampleSize, "ZSTD_decompress failed (%s) (srcSize : %u ; cSize : %u)", ZSTD_getErrorName(dSize), (U32)sampleSize, (U32)cSize);
|
CHECK(dSize != sampleSize, "ZSTD_decompress failed (%s) (srcSize : %u ; cSize : %u)", ZSTD_getErrorName(dSize), (U32)sampleSize, (U32)cSize);
|
||||||
crcDest = XXH64(dstBuffer, sampleSize, 0);
|
crcDest = XXH64(dstBuffer, sampleSize, 0);
|
||||||
CHECK(crcOrig != crcDest, "decompression result corrupted (pos %u / %u)", (U32)findDiff(srcBuffer+sampleStart, dstBuffer, sampleSize), (U32)sampleSize);
|
CHECK(crcOrig != crcDest, "decompression result corrupted (pos %u / %u)", (U32)findDiff(sampleBuffer, dstBuffer, sampleSize), (U32)sampleSize);
|
||||||
|
|
||||||
|
free(sampleBuffer); /* no longer useful after this point */
|
||||||
|
|
||||||
/* truncated src decompression test */
|
/* truncated src decompression test */
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user