gh-150583: Fix zstd compression with digested ZstdDict#150586
Open
Rogdham wants to merge 1 commit into
Open
Conversation
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.
Changes
Force setting a
compression_levelofZSTD_CLEVEL_DEFAULTwhen creating theZstdCompressorobject.Question for reviewers: should I use
_zstd_set_c_level(ZSTD_CLEVEL_DEFAULT)instead?See reproducer in #150583.
Analysis
When creating a
ZstdCompressorobject (_zstd_ZstdCompressor_new_impl), thecompression_levelfield is unset, and as a result keeps its value from whatever was in memory (not deterministic), assuming no level is passed in the constructor.Then, when set, the C dict is loaded into the compression context with
_zstd_load_c_dict, which in turn calls_zstd_load_impl.In the case of a digested dictionary,
_get_CDict(zd, self->compression_level)is now called, which in turns callsZSTD_createCDict(..., compressionLevel).So an arbitrary compression level is passed to that call to
libzstd.Bug impact
Prerequisites:
compression.zstdlevelnor throughoptions)zstd_dict(e.g. withZstdDict(...).as_digested_dict)Consequence: the compression level used is arbitrary, and may change from one run to another.
Misc
Backport suggestion: to 3.15 and 3.14.
AI disclosure: analysis was performed with help of an LLM.
@emmatyping 👋