Repository navigation
Conversation
- In ZDICT_trainFromBuffer_fastCover(), check that segmentFreqs allocation succeeded before use. On allocation failure, destroy ctx and return ERROR(memory_allocation) to prevent an immediate NULL pointer dereference crash and memory leak. - In ZDICT_addEntropyTablesFromBuffer_advanced(), validate dictBuffer != NULL, dictBufferCapacity >= dictContentSize, and dictBufferCapacity >= ZDICT_DICTSIZE_MIN to prevent size_t underflow in (dictBufferCapacity - dictContentSize) and out-of-bounds reads in XXH64, ZDICT_analyzeEntropy, and memmove. - In ZDICT_finalizeDictionary(), validate dictBuffer != NULL before any buffer copy operations. - Add regression tests in tests/fuzzer.c exercising invalid capacities and NULL buffer arguments. Signed-off-by: Filippo Tedeschi <filippotedeschi98@gmail.com>
Author
|
Closing. The calloc of 2^f U16 in ZDICT_trainFromBuffer_fastCover() is half |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses several input validation and memory safety issues in
lib/dictBuilder:ZDICT_trainFromBuffer_fastCover()(lib/dictBuilder/fastcover.c):segmentFreqs = (U16 *)calloc(((U64)1 << parameters.f), sizeof(U16));was not checked for allocation failure (unlikeFASTCOVER_tryParameters(), which checksif (!segmentFreqs || !dict || !freqs)).callocfails (e.g. OOM or largeparameters.f),FASTCOVER_buildDictionary()->FASTCOVER_selectSegment()dereferencessegmentFreqs[idx] += 1;on a NULL pointer, causing an immediate segmentation fault and leakingctx.if (!segmentFreqs), destroyingctxand returningERROR(memory_allocation).ZDICT_addEntropyTablesFromBuffer_advanced()(lib/dictBuilder/zdict.c):ZDICT_addEntropyTablesFromBuffer().dictBufferCapacity < dictContentSize, the pointer calculation(char*)dictBuffer + dictBufferCapacity - dictContentSizeunderflowssize_t, producing an out-of-bounds pointer precedingdictBufferthat is subsequently passed toXXH64,ZDICT_analyzeEntropy, andmemmove.dictBuffer == NULLordictBufferCapacity < ZDICT_DICTSIZE_MIN, writing dictionary headers leads to null dereference or out-of-bounds writes.ZDICT_finalizeDictionary(), returningERROR(dstSize_tooSmall).ZDICT_finalizeDictionary()(lib/dictBuilder/zdict.c):dictBuffer != NULLupfront before copying headers and content.Tests (
tests/fuzzer.c):