Repository navigation
Conversation
When decompressing a malformed frame header using a single-use prefix (ZSTD_DCtx_refPrefix), decompression aborts before ZSTD_getDDict() can consume the dictionary. A subsequent ZSTD_DCtx_reset(session_only) reset streamStage back to zdss_init without clearing dictUses == ZSTD_use_once, allowing the discarded prefix buffer to leak into subsequent frames and causing heap use-after-free if the caller freed the prefix buffer. Clear the prefix during session reset if a frame decompression was already initiated (dctx->streamStage != zdss_init). Add regression tests in zstreamtest to verify that the prefix is dropped after a bad header and preserved if reset occurs prior to ingesting input. Fixes meta#4843
This branch has not been deployed
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.
Fixes #4843
When decompressing a malformed frame header using a single-use prefix (ZSTD_DCtx_refPrefix), decompression aborts before ZSTD_getDDict() can consume the dictionary. A subsequent ZSTD_DCtx_reset(session_only) reset streamStage back to zdss_init without clearing dictUses == ZSTD_use_once, allowing the discarded prefix buffer to leak into subsequent frames and causing heap use-after-free if the caller freed the prefix buffer.
Clear the prefix during session reset if a frame decompression was already initiated (dctx->streamStage != zdss_init). Add regression tests in zstreamtest to verify that the prefix is dropped after a bad header and preserved if reset occurs prior to ingesting input.
This change clears the prefix during session reset if a frame decompression was already initiated (
dctx->streamStage != zdss_init).Regression tests have been added to
tests/zstreamtest.cto verify that:Checklist
A gain in one configuration is not a general gain: see the Performance section of CONTRIBUTING.md.
Tools used
Byteask was used for root cause diagnosis, implementing the fix in
zstd_decompress.c, and writing the regression tests inzstreamtest.c.