Skip to content

Reset CCtx session after successful simple one-shot compression - #4987

Open
mzfr wants to merge 1 commit into
meta:devfrom
mzfr:fix/simple-one-shot-session-boundary
Open

mzfr wants to merge 1 commit into
meta:devfrom
mzfr:fix/simple-one-shot-session-boundary

Conversation

@mzfr

@mzfr mzfr commented Nov 18, 2026 •

Copy link
Copy Markdown

What and why

ZSTD_compressCCtx(), ZSTD_compress_usingDict(), and ZSTD_compress_usingCDict() install the one-shot input size as the current frame pledge, but leave that pledge in the context after successful compression. Reusing the same context for a differently sized streaming job can therefore fail with ZSTD_error_srcSize_wrong before consuming input.

Route the shared simple one-shot completion paths through a helper that resets the session after a successful frame. The session-only reset clears frame-local streaming state, including the pledged source size, while keeping requested parameters and referenced dictionaries. Failed one-shot operations retain the existing error-state behavior, and the public bufferless ZSTD_compressBegin() / ZSTD_compressContinue() / ZSTD_compressEnd() API is unchanged.

The regression test covers all three public simple one-shot variants with an empty one-shot followed by a 12-byte ZSTD_e_continue streaming job. It also compares the resulting frame with a reference context to verify that sticky parameters and a referenced CDict survive the new session boundary.

Checklist

  • I searched open pull requests and issues: this problem is not already being addressed.
  • Bug fix: it comes with a reproducer or a test that fails without the fix.
  • Performance change: numbers from repeated runs are included, with CPU, compiler, flags and data.
    A gain in one configuration is not a general gain: see the Performance section of CONTRIBUTING.md.
  • I stated below whether AI or other automated tools were used.

Tests

  • Focused reproducer, normal, ASan, and UBSan builds:
    24-cctx, 24-usingdict, 24-cdict, 24-compress2-control,
    24-reset-control, and 24-same-size-control
  • make -C tests test-fuzzer FUZZERTEST='-i0 -s1'
  • make -C tests test-zstream ZSTREAM_TESTTIME='-T10s'
  • make check

Tools used

I used GPT-5.6-Sol for everything from finding the bug to fixing it, writing the patch, generating tests, and preparing the PR description.

@meta-cla

meta-cla Bot commented Nov 18, 2026

Copy link
Copy Markdown

Hi @mzfr!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Nov 18, 2026
@meta-cla

meta-cla Bot commented Nov 18, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant