Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/compress/zstd_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -2536,7 +2536,8 @@ static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx,
ZSTD_MatchState_t* dstMatchState = &cctx->blockState.matchState;
dstMatchState->window = srcMatchState->window;
dstMatchState->nextToUpdate = srcMatchState->nextToUpdate;
dstMatchState->loadedDictEnd= srcMatchState->loadedDictEnd;
/* with forceWindow, the dictionary is only reachable within the window */
dstMatchState->loadedDictEnd= params.forceWindow ? 0 : srcMatchState->loadedDictEnd;
}

cctx->dictID = cdict->dictID;
Expand Down
32 changes: 32 additions & 0 deletions tests/fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4223,6 +4223,38 @@ static int basicUnitTests(U32 const seed, double compressibility)
}
DISPLAYLEVEL(3, "OK \n");

DISPLAYLEVEL(3, "test%3i : forceMaxWindow with a referenced CDict : ", testNb++);
{ /* The source repeats the start of a 64 KB dictionary. With a 1 KB window and
* forceMaxWindow, no match may reach that far back into the dictionary. */
unsigned const windowLog = 10;
size_t const dictSize = 64 KB;
size_t const srcSize = 8 KB;
size_t const seqsCapacity = ZSTD_sequenceBound(srcSize);
void* const dict = malloc(dictSize);
ZSTD_Sequence* const seqs = (ZSTD_Sequence*)malloc(seqsCapacity * sizeof(ZSTD_Sequence));
ZSTD_CCtx* const cctx = ZSTD_createCCtx();
ZSTD_CDict* cdict;
size_t nbSeqs, u;

if (dict == NULL || seqs == NULL || cctx == NULL) goto _output_error;
RDG_genBuffer(dict, dictSize, 0., 0., seed);
memcpy(CNBuffer, dict, srcSize);
cdict = ZSTD_createCDict(dict, dictSize, 3);
if (cdict == NULL) goto _output_error;
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, (int)windowLog));
CHECK_Z(ZSTD_CCtx_setParameter(cctx, ZSTD_c_forceMaxWindow, 1));
CHECK_Z(ZSTD_CCtx_refCDict(cctx, cdict));
CHECK_VAR(nbSeqs, ZSTD_generateSequences(cctx, seqs, seqsCapacity, CNBuffer, srcSize));
for (u = 0; u < nbSeqs; ++u)
CHECK_LT(seqs[u].offset, (1U << windowLog) + 1);

ZSTD_freeCCtx(cctx);
ZSTD_freeCDict(cdict);
free(seqs);
free(dict);
}
DISPLAYLEVEL(3, "OK \n");

DISPLAYLEVEL(3, "test%3i : testing dict compression for determinism : ", testNb++);
{
size_t const testSize = 1024;
Expand Down