| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Caution Review failedThe pull request is closed. Configuration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 52a6b775-af26-45f6-a6ba-752d76a19e37 📥 CommitsReviewing files that changed from the base of the PR and between c074556 and 57accdb. 📒 Files selected for processing (1)
📝 Walkthrough WalkthroughThis PR tightens BLOB setitem: single-index assignments now require a PyInt converted to i64 and must be 0–255; non-unit-step extended-slice assignments preserve unaffected bytes by reading the destination span first. A RustPython-only regression test verifies negative-step slice behavior. ChangesBLOB item assignment improvements
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem🚥 Pre-merge checks | ✅ 4 | ❌ 1 ❌ Failed checks (1 warning)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches 🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/sqlite3 dependencies:
dependent tests: (2 tests)
Legend:
|
Sorry, something went wrong.
Previously, assigning an out-of-range integer (negative or > 255) or an
integer too large for i64 (e.g. 2**65) to a Blob index raised OverflowError
instead of ValueError.
Mirror CPython's ass_subscript_index logic:
- Convert the value via to_i64(), treating any overflow as -1
- Validate the result is in [0, 255], raising ValueError("byte must be in range(0, 256)") otherwise
- Separate deletion error messages: "item deletion" for index, "slice deletion" for slice
In the step != 1 branch of Blob.ass_subscript, the loop used i_in_temp += step as usize where step is isize. For negative steps (e.g. step = -2), (-2isize) as usize = 18446744073709551614 causing an out-of-bounds panic whenever slice_len >= 2. Fix: use SaturatedSliceIter (already used by the read path) to iterate over the correct absolute blob indices, then map each index back to a temp buffer offset via abs_idx - range_start. Also fix a Clippy lint: replace val < 0 || val > 255 with the idiomatic !(0..=255).contains(&val) Add a regression test in extra_tests/snippets/stdlib_sqlite.py that exercises blob[9:0:-2] (negative step, slice_len=5).
Why the snippet test is guarded by sys.implementation.name == "rustpython"CI was failing because CPython 3.14 also has a bug with negative-step Blob slice assignment. Running blob[9:0:-2] = b"12345" under CPython 3.14 raises: SystemError: Negative size passed to PyBytes_FromStringAndSizeThe root cause is in CPython's Modules/_sqlite/blob.c, inside ass_subscript_slice: // For blob[9:0:-2], PySlice_AdjustIndices gives start=9, stop=0, step=-2
PyObject *blob_bytes = read_multiple(self, stop - start, start);
// 0 - 9 = -9 ← negative!
// PyBytes_FromStringAndSize(NULL, -9) → SystemErrorWhen step is negative, stop < start, so stop - start is negative, and passing that to PyBytes_FromStringAndSize triggers an internal assertion error. This is a CPython-side bug — both CPython and RustPython had a broken implementation of negative-step Blob slice writes (CPython raises SystemError, RustPython previously panicked). This PR fixes the RustPython side. The snippet test validates RustPython's fix but cannot run on CPython until the upstream bug is resolved, hence the guard. Reference
|
Sorry, something went wrong.
| # this test only runs on RustPython where the fix is being validated. | ||
| import sys | ||
|
|
||
| if sys.implementation.name == "rustpython": |
There was a problem hiding this comment.
we usually don't add rustpython-only code. is this CPython bug? Then is this reported to CPython?
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, the negative-step slice crash is a CPython bug — I've filed it upstream as python/cpython#150449 and submitted a fix PR (python/cpython#150450).
However, this PR also contains a few pre-existing RustPython-only bugs unrelated to that CPython issue:
Should I split this into two PRs — one for the CPython-mirrored negative-step fix (which could be reverted or marked TODO: RUSTPYTHON until upstream lands), and one for the RustPython-specific behavior alignment?
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks!
Sorry, something went wrong.
* sqlite3: fix Blob.__setitem__ value range validation
Previously, assigning an out-of-range integer (negative or > 255) or an
integer too large for i64 (e.g. 2**65) to a Blob index raised OverflowError
instead of ValueError.
Mirror CPython's ass_subscript_index logic:
- Convert the value via to_i64(), treating any overflow as -1
- Validate the result is in [0, 255], raising ValueError("byte must be in range(0, 256)") otherwise
- Separate deletion error messages: "item deletion" for index, "slice deletion" for slice
* sqlite3: fix Blob.__setitem__ negative-step slice write
In the step != 1 branch of Blob.ass_subscript, the loop used
i_in_temp += step as usize
where step is isize. For negative steps (e.g. step = -2),
(-2isize) as usize = 18446744073709551614
causing an out-of-bounds panic whenever slice_len >= 2.
Fix: use SaturatedSliceIter (already used by the read path) to iterate
over the correct absolute blob indices, then map each index back to a
temp buffer offset via abs_idx - range_start.
Also fix a Clippy lint: replace
val < 0 || val > 255
with the idiomatic
!(0..=255).contains(&val)
Add a regression test in extra_tests/snippets/stdlib_sqlite.py that
exercises blob[9:0:-2] (negative step, slice_len=5).
* fix: guard blob negative-step snippet from CPython 3.11 bug
* style: add blank line after import sys in stdlib_sqlite snippet (ruff)
* Update extra_tests/snippets/stdlib_sqlite.py
---------
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
| Back | FazBrowse Home | New Git URL |
Previously, assigning an out-of-range integer (negative or > 255) or an integer too large for i64 (e.g. 2**65) to a Blob index raised OverflowError instead of ValueError.
Mirror CPython's ass_subscript_index logic:
Ref: https://github.com/python/cpython/blob/main/Modules/_sqlite/blob.c
Problem
When assigning an out-of-range integer to a Blob index, RustPython raised OverflowError instead of ValueError:
CPython raises ValueError: byte must be in range(0, 256) for all three cases.
Root Cause
The previous implementation used try_to_primitive::<u8>(vm)? to convert the assigned value, which calls Rust's type conversion and raises a generic OverflowError for any value that doesn't fit in u8 — including negative numbers.
Fix
Mirrors CPython's ass_subscript_index logic:
In Rust:
Additionally, aligned the deletion error messages with CPython:
Changes
Summary by CodeRabbit
Bug Fixes
Tests