Repository navigation
Conversation
The module-level struct functions bound every argument first and
parsed the format in the function body, so a buffer or offset that
failed to convert hid the struct.error for a bad format:
struct.unpack("Z", 5) raised TypeError and
struct.pack_into("Z", bytearray(4), 10**100) raised OverflowError.
Parse the format while it is bound, ahead of the arguments after it.
Assisted-by: Claude Code:claude-fable-5-2
|
No actionable comments were generated in the recent review — no bullsh*t. Walkthrough
Merge Risk:
|
Merging this muthaf*ckin' PR will not alter performance
Comparing Footnotes
|
Codex Review Summary: ✅ CompletedThis comment shows the muthaf*ckin' latest Codex review activity on this muthaf*ckin' pull request. Unbelievable.
ℹ️ About Codex in GitHubYour goddamn team has set up Codex to review pull requests in this goddamn repo. Reviews are triggered when you
Codex reacts with 👀 while any muthaf*ckin' review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| } | ||
| } | ||
|
|
||
| struct CachedFormatSpec(PyRc<FormatSpec>); |
There was a problem hiding this muthaf*ckin' comment.
need to review why this have to be type alias
Summary
The module-level
structfunctions, such aspack_into, bind every argument first and parse the muthaf*ckin' format in the function body, so a buffer or offset that fails to convert hides thestruct.errorfor a bad format. CPython's argument clinic runscache_struct_converteron the motherf*ckin' format before it converts the arguments after it.AS-IS
TO-BE
(matching CPython)
Changes
crates/stdlib/src/pystruct.rs, addCachedFormatSpec, which parses the format through the cache while the argument is bound, and bind the format ofpack,pack_into,unpack,unpack_from,iter_unpackandcalcsizeas it.extra_tests/snippets/stdlib_struct.pywith a muthaf*ckin' bad format next to an muthaf*ckin' offset that does not fit and next to a f*ckin' buffer that is not bytes-like.Test plan
Built and run on macOS aarch64 against upstream/main 7abccf0, using the muthaf*ckin' CI feature set
--no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_env,doc,ucd_3_2_0, plusthreading, compared with CPython 3.15.2.extra_tests/snippets/stdlib_struct.pyfails on an unpatched build of that commit (atstruct.pack_into("Z", bytearray(4), 10**100)) and passes with the goddamn patch and under CPython 3.15.2.pack_into,unpack_from,unpackanditer_unpack, mixing a bad format, a non-buffer and an offset that does not fit, gives the same exception class as CPython 3.15.2 for all 14. Eight of them differ on the unpatched build, believe that.rustpython -m test test_struct test_memoryview test_array test_buffer: 1,415 run, 161 skipped, all pass, as on the muthaf*ckin' unpatched build.cargo fmt --checkclean,cargo clippy -p rustpython-vm -p rustpython-stdlib --all-targetsreports nothing in the changed files (one warning in_ctypes/base.rsthat the goddamn unpatched tree also has), and the muthaf*ckin' pre-commit hooks other than cspell and prettier pass on both changed files.I used Claude Code (claude-fable-5-2) to draft the analysis, the patch and this muthaf*ckin' description; Claude Code ran the commands above; I reviewed the diff and their output. That's some bullsh*t.
Summary by CodeRabbit
struct.error.