Repository navigation
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.
Add
_zstdstdlib module backingcompression.zstd#7962New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add
_zstdstdlib module backingcompression.zstd#7962Changes from 1 commit
9e5c27f1def1b4ee26123fbce9c963103b677370cbace862f07aa356f7598d69b1e29ee6c5b19dbe46269d497f48fe59b83d4825e52bea59133514868bed04e163561041f6312cc95470880de2c588dcb6751a6235417425c591e7File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Found by reviewing the module against CPython's `Modules/_zstd/` and the pinned libzstd-rs-sys sources; each item below was reproduced before the fix and re-checked after. - `train_dict`/`finalize_dict` sized their output buffer with an infallible `Vec::with_capacity`/`vec![]` from a caller-supplied `dict_size`, so `train_dict([b'x'], 2**62)` aborted the interpreter instead of raising. Reserve fallibly and raise `MemoryError`, as CPython does. - A digested dictionary was always built at `ZSTD_CLEVEL_DEFAULT`. Since `ZSTD_CCtx_refCDict` takes its parameters from the CDict, that silently discarded the requested level: `level=19` with `as_digested_dict` compressed a test corpus to 39817 bytes instead of 31951. Build the CDict at the compressor's effective level, tracked through `level=` and the `options` dict like CPython's `self->compression_level`. - A bare `ZstdDict` was loaded as digested in both directions; CPython compresses with an undigested dictionary by default and only decompresses with a digested one. Give `DictLoader` a per-direction default. - Neither compressor nor decompressor reset its session after an error, leaving the object permanently broken — every later call failed with "Operation not authorized at current processing stage" or re-reported the original corruption on valid input. Reset as CPython's error paths do, including restoring `last_mode` to `FLUSH_FRAME`. - `apply_options` range-checked every parameter, rejecting values libzstd and CPython accept: 0 ("use the default") for `window_log`, `strategy`, `window_log_max` and friends, any non-zero value for the boolean flags, and the clamped `nb_workers`/`job_size`/`overlap_log`. Only `compression_level` needs the check — libzstd clamps that one silently, which is why `test_compress_parameters` requires a `ValueError` — so everything else now goes to libzstd, whose error code already maps to the same message. - `ZstdDict` accepted content shorter than 8 bytes; CPython rejects it up front regardless of `is_raw`. - `compress`/`decompress` refused `data` as a keyword and `get_param_bounds` required `is_compress` as one, both contrary to CPython's clinic signatures. - The decompressor allocated a full 128 KiB scratch buffer even when `max_length` capped output far below that. `test_zstd` (119 tests) and the snippet test pass; clippy is clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
Uh oh!
There was an error while loading. Please reload this page.