Commit ce79cd4
sqlite3: fix Blob.__setitem__ value range validation (RustPython#7981)
* 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>1 parent dcb273b commit ce79cd4
3 files changed
Lines changed: 38 additions & 14 deletions
File tree
- Lib/test/test_sqlite3
- crates/stdlib/src
- extra_tests/snippets
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1444 | 1444 | | |
1445 | 1445 | | |
1446 | 1446 | | |
1447 | | - | |
1448 | 1447 | | |
1449 | 1448 | | |
1450 | 1449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
2551 | 2552 | | |
2552 | 2553 | | |
2553 | 2554 | | |
2554 | | - | |
2555 | | - | |
2556 | | - | |
2557 | 2555 | | |
2558 | 2556 | | |
2559 | 2557 | | |
2560 | 2558 | | |
2561 | 2559 | | |
2562 | | - | |
| 2560 | + | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
2563 | 2564 | | |
2564 | 2565 | | |
2565 | 2566 | | |
2566 | 2567 | | |
2567 | 2568 | | |
2568 | | - | |
2569 | 2569 | | |
2570 | 2570 | | |
2571 | | - | |
2572 | | - | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
| 2577 | + | |
2573 | 2578 | | |
2574 | 2579 | | |
2575 | 2580 | | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
2576 | 2584 | | |
2577 | 2585 | | |
2578 | 2586 | | |
| |||
2604 | 2612 | | |
2605 | 2613 | | |
2606 | 2614 | | |
| 2615 | + | |
2607 | 2616 | | |
2608 | 2617 | | |
2609 | 2618 | | |
2610 | 2619 | | |
2611 | 2620 | | |
2612 | | - | |
| 2621 | + | |
2613 | 2622 | | |
2614 | 2623 | | |
2615 | 2624 | | |
2616 | | - | |
2617 | | - | |
2618 | | - | |
2619 | | - | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
2620 | 2628 | | |
2621 | 2629 | | |
2622 | 2630 | | |
2623 | 2631 | | |
2624 | 2632 | | |
2625 | | - | |
| 2633 | + | |
2626 | 2634 | | |
2627 | 2635 | | |
2628 | 2636 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
0 commit comments