Repository navigation
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.
Interpolate the three error messages in the CFFI compression reader before passing them to
ZstdError, matching the C extension and the existingread1()/readinto1()end-of-stream paths. Passing the format string and error text as separate exception arguments leaves%sunexpanded and renders a tuple instead of the intended message. Thanks to @devdanzin for reporting this in the message-formatting part of #301. This change addresses that part of the report; the lifecycle and parameter-validation topics remain outside its scope.Reproducer (run once with
PYTHON_ZSTANDARD_IMPORT_POLICY=cffiand once withPYTHON_ZSTANDARD_IMPORT_POLICY=cext):Observed output on Python 3.12.13 with Zstandard 1.5.7 (
exc.args;str(exc)):cffi('zstd compress error: %s', 'Src size is incorrect');('zstd compress error: %s', 'Src size is incorrect')('zstd compress error: Src size is incorrect',);zstd compress error: Src size is incorrectcext('zstd compress error: Src size is incorrect',);zstd compress error: Src size is incorrectcffi('error ending compression stream: %s', 'Src size is incorrect');('error ending compression stream: %s', 'Src size is incorrect')('error ending compression stream: Src size is incorrect',);error ending compression stream: Src size is incorrectcext('error ending compression stream: Src size is incorrect',);error ending compression stream: Src size is incorrectThe regression test uses a fresh reader for each of
read,readinto,read1, andreadinto1, with both under-declared and over-declared source sizes. It checks a single exception argument, interpolation, and exact messages shared by the two backends. Size 2 reaches_compress_into_buffer()through all four methods; size 42 reaches each method's end-of-stream path. All three changed raises are exercised. On the original CFFI code, six of the eight subtests fail; the two already formatted end-of-stream methods pass. All eight pass with the fix and with the C extension.Validation on macOS arm64 / Python 3.12.13, with each backend explicitly selected:
Dependencies were installed from
uv.lock; both native backends were built withZSTD_WARNINGS_AS_ERRORS=1. These are the complete default suites; optional slow/fuzz tests were not enabled. Ruff 0.17.2 passes for the repository, and both changed files pass its format check. The full CI platform matrix has not been run locally.AI disclosure: Codex assisted with part of the code and this description.