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
6 changes: 6 additions & 0 deletions lib/dictBuilder/fastcover.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ FASTCOVER_ctx_init(FASTCOVER_ctx_t* ctx,
return ERROR(srcSize_wrong);
}

/* Check the training set can hold at least one dmer, otherwise nbDmers underflows below */
if (trainingSamplesSize < MAX(d, sizeof(U64))) {
DISPLAYLEVEL(1, "Total training samples size is %u and is invalid.\n", (unsigned)trainingSamplesSize);
return ERROR(srcSize_wrong);
}

/* Zero the context */
memset(ctx, 0, sizeof(*ctx));
DISPLAYLEVEL(2, "Training on %u samples of total size %u\n", nbTrainSamples,
Expand Down
10 changes: 10 additions & 0 deletions tests/fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3060,6 +3060,16 @@ static int basicUnitTests(U32 const seed, double compressibility)
if (ZDICT_isError(dictSize)) goto _output_error;
DISPLAYLEVEL(3, "OK, created dictionary of size %u \n", (unsigned)dictSize);

DISPLAYLEVEL(3, "test%3i : FASTCOVER dictBuilder samples smaller than a dmer (issue #4499) : ", testNb++);
{ const char smallData[8] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
const size_t smallSizes[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
size_t const r = ZDICT_trainFromBuffer(dictBuffer, dictBufferCapacity,
smallData, smallSizes, 8);
if (!ZDICT_isError(r)) goto _output_error;
if (ZSTD_getErrorCode(r) != ZSTD_error_srcSize_wrong) goto _output_error;
}
DISPLAYLEVEL(3, "OK \n");

DISPLAYLEVEL(3, "test%3i : Multithreaded COVER dictBuilder : ", testNb++);
{ U32 u; for (u=0; u<nbSamples; u++) samplesSizes[u] = sampleUnitSize; }
{ ZDICT_cover_params_t coverParams;
Expand Down
Loading