validated external dictionary

This commit is contained in:
Yann Collet 2015-12-06 13:18:37 +01:00
parent e47c4e5f8e
commit 4bfe415fa7
2 changed files with 16 additions and 3 deletions

View File

@ -538,13 +538,13 @@ FORCE_INLINE size_t ZSTD_execSequence(BYTE* op,
match = dictEnd - (base-match); match = dictEnd - (base-match);
if (match + sequence.matchLength <= dictEnd) if (match + sequence.matchLength <= dictEnd)
{ {
memcpy(oLitEnd, match, sequence.matchLength); memmove(oLitEnd, match, sequence.matchLength);
return sequenceLength; return sequenceLength;
} }
/* span extDict & currentPrefixSegment */ /* span extDict & currentPrefixSegment */
{ {
size_t length1 = dictEnd - match; size_t length1 = dictEnd - match;
memcpy(oLitEnd, match, length1); memmove(oLitEnd, match, length1);
op = oLitEnd + length1; op = oLitEnd + length1;
sequence.matchLength -= length1; sequence.matchLength -= length1;
match = base; match = base;

View File

@ -309,6 +309,8 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
U64 crcOrig, crcDest; U64 crcOrig, crcDest;
int cLevel; int cLevel;
BYTE* sampleBuffer; BYTE* sampleBuffer;
const BYTE* dict;
size_t dictSize;
/* init */ /* init */
if (nbTests >= testNb) if (nbTests >= testNb)
@ -451,8 +453,18 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
maxTestSize = (size_t)1 << sampleSizeLog; maxTestSize = (size_t)1 << sampleSizeLog;
maxTestSize += FUZ_rand(&lseed) & (maxTestSize-1); maxTestSize += FUZ_rand(&lseed) & (maxTestSize-1);
if (maxTestSize >= dstBufferSize) maxTestSize = dstBufferSize-1; if (maxTestSize >= dstBufferSize) maxTestSize = dstBufferSize-1;
totalTestSize = 0;
sampleSizeLog = FUZ_rand(&lseed) % maxSampleLog;
sampleSize = (size_t)1 << sampleSizeLog;
sampleSize += FUZ_rand(&lseed) & (sampleSize-1);
sampleStart = FUZ_rand(&lseed) % (srcBufferSize - sampleSize);
dict = srcBuffer + sampleStart;
dictSize = sampleSize;
cSize = ZSTD_compressBegin(ctx, cBuffer, cBufferSize, (FUZ_rand(&lseed) % (20 - (sampleSizeLog/3))) + 1); cSize = ZSTD_compressBegin(ctx, cBuffer, cBufferSize, (FUZ_rand(&lseed) % (20 - (sampleSizeLog/3))) + 1);
errorCode = ZSTD_compress_insertDictionary(ctx, dict, dictSize);
CHECK (ZSTD_isError(errorCode), "dictionary insertion error : %s", ZSTD_getErrorName(errorCode));
totalTestSize = 0;
for (n=0; n<nbChunks; n++) for (n=0; n<nbChunks; n++)
{ {
sampleSizeLog = FUZ_rand(&lseed) % maxSampleLog; sampleSizeLog = FUZ_rand(&lseed) % maxSampleLog;
@ -481,6 +493,7 @@ int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compressibilit
/* streaming decompression test */ /* streaming decompression test */
errorCode = ZSTD_resetDCtx(dctx); errorCode = ZSTD_resetDCtx(dctx);
CHECK (ZSTD_isError(errorCode), "cannot init DCtx : %s", ZSTD_getErrorName(errorCode)); CHECK (ZSTD_isError(errorCode), "cannot init DCtx : %s", ZSTD_getErrorName(errorCode));
ZSTD_decompress_insertDictionary(dctx, dict, dictSize);
totalCSize = 0; totalCSize = 0;
totalGenSize = 0; totalGenSize = 0;
while (totalCSize < cSize) while (totalCSize < cSize)