Commit 24ade8a
committed
gh-150449: Fix sqlite3.Blob crash with negative-step slices
Reading or writing a sqlite3.Blob with a negative-step slice such as
blob[9:0:-2] caused a crash (SystemError on older versions, ValueError
on current main) because the C code computed stop - start as the read
length, which is negative for negative steps.
Fix subscript_slice() and ass_subscript_slice() in Modules/_sqlite/blob.c
to handle both positive and negative steps correctly:
- For step > 1: keep reading [start, stop) and indexing forward as before.
- For step < -1: read the contiguous range [start+(len-1)*step, start]
and index backward with stride -step.1 parent 629da5c commit 24ade8a
3 files changed
Lines changed: 74 additions & 8 deletions
File tree
- Lib/test/test_sqlite3
- Misc/NEWS.d/next/Library
- Modules/_sqlite
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1390 | 1390 | | |
1391 | 1391 | | |
1392 | 1392 | | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
1393 | 1399 | | |
1394 | 1400 | | |
1395 | 1401 | | |
| |||
1406 | 1412 | | |
1407 | 1413 | | |
1408 | 1414 | | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
1409 | 1430 | | |
1410 | 1431 | | |
1411 | 1432 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
448 | | - | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
449 | 462 | | |
450 | 463 | | |
451 | 464 | | |
| |||
456 | 469 | | |
457 | 470 | | |
458 | 471 | | |
459 | | - | |
460 | 472 | | |
461 | | - | |
462 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
463 | 484 | | |
464 | 485 | | |
465 | 486 | | |
| |||
549 | 570 | | |
550 | 571 | | |
551 | 572 | | |
552 | | - | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
553 | 587 | | |
554 | 588 | | |
555 | | - | |
556 | | - | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
557 | 599 | | |
558 | | - | |
| 600 | + | |
559 | 601 | | |
560 | 602 | | |
561 | 603 | | |
| |||
0 commit comments