Repository navigation
Clear Zstandard prefixes and restore dictionaries on reset - #136209
Merged
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression |
Co-authored-by: Copilot App <[email protected]>
Member
Author
|
/backport to release/11.0 |
Contributor
|
Started backporting to |
svick
pushed a commit
that referenced
this pull request
Oct 27, 2026
…eset (#136307) Backport of #136209 to release/11.0 /cc @rzikm ## Customer Impact In rare scenarios when reusing ZstandardDecoder in scenarios with and without prefixes, the decoder could reuse the previous prefix after reset, potentially causing unexpected/corrupted output. ## Regression No, Zstandard is a new feature in 11.0 ## Testing New tests added to run as part of CI. ## Risk Low, fix is well understood and small. Co-authored-by: Radek Zikmund <[email protected]>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Zstandard's session-only reset preserves an unused prefix, but the managed encoder and decoder release its pinned memory. This leaves the native context referencing memory that is no longer pinned. Setting a prefix also replaces the constructor-supplied dictionary without restoring it on reset.
Update both reset paths to restore the original dictionary, or explicitly clear the native prefix when no dictionary was supplied, before releasing the pinned memory. Document the prefix override and dictionary restoration behavior.
Extend the existing reset test with dictionary/no-dictionary and empty/nonempty prefix cases. Cover reset before prefix use and after a completed frame, compare reset encoder output with a fresh encoder, and independently verify decoder dictionary restoration.
Validation
Ran from
src\libraries\System.IO.Compressionusing the repository SDK and a shortsubstpath:U:\dotnet.cmd build- passed.U:\dotnet.cmd build /t:Test tests\System.IO.Compression.Tests.csproj- passed, 2,655 tests, zero failures (outer-loop tests excluded).U:\dotnet.cmd build /t:Test tests\System.IO.Compression.Tests.csproj /p:XunitMethodName=System.IO.Compression.ZstandardEncoderDecoderTests.SetPrefix_AfterReset_SetsSuccessfully- passed, all four cases.Confirmed the expanded test fails without encoder dictionary restoration and, with only the encoder fixed, catches both decoder prefix clearing and dictionary restoration failures.
Note
This pull request description was generated by GitHub Copilot.