Repository navigation
Commit 35e2c5a
authored
* gh-160303: Fix bytearray state after a failed del b[:n]
When shrinking the storage of a bytearray which has a logical offset,
allocate the new buffer before modifying the object, so that
bytearray_setslice_linear() can restore ob_start if the allocation fails.
* gh-160303: Keep ob_start instead of allocating in del b[:n]
Move ob_start and the size before the shrinking resize, so a failed
shrink leaves the bytes removed and the larger block in place, as the
non-front path already does. Split the checks out of
bytearray_resize_lock_held() so the slice code can resize directly.
Move the tests into test_resize_error.
* gh-160303: Test failed shrinks not at the front; narrow the unchecked resize
Only the front path of bytearray_setslice_linear() calls
bytearray_resize_unchecked(): it has already advanced ob_start and reduced
the size, so bytearray_resize_lock_held() would return early without
releasing memory. Other slices go through bytearray_resize_lock_held()
again and keep the failure fixup to themselves.
test_resize_error now also covers slices in the middle and at the end,
and checks the null byte after the data with float().
1 parent 9f03afd commit 35e2c5a
3 files changed
Lines changed: 91 additions & 38 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Objects
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1661 | 1661 | | |
1662 | 1662 | | |
1663 | 1663 | | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
1664 | 1668 | | |
1665 | 1669 | | |
1666 | 1670 | | |
| |||
1687 | 1691 | | |
1688 | 1692 | | |
1689 | 1693 | | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
1690 | 1721 | | |
1691 | 1722 | | |
1692 | 1723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
269 | 276 | | |
270 | | - | |
| 277 | + | |
271 | 278 | | |
272 | | - | |
273 | | - | |
| 279 | + | |
| 280 | + | |
274 | 281 | | |
275 | 282 | | |
| 283 | + | |
| 284 | + | |
276 | 285 | | |
277 | 286 | | |
278 | 287 | | |
279 | 288 | | |
280 | 289 | | |
281 | 290 | | |
282 | 291 | | |
283 | | - | |
284 | | - | |
285 | 292 | | |
286 | 293 | | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | 294 | | |
301 | 295 | | |
302 | 296 | | |
| |||
348 | 342 | | |
349 | 343 | | |
350 | 344 | | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
351 | 369 | | |
352 | 370 | | |
353 | 371 | | |
| |||
612 | 630 | | |
613 | 631 | | |
614 | 632 | | |
615 | | - | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
616 | 636 | | |
| 637 | + | |
617 | 638 | | |
618 | 639 | | |
619 | 640 | | |
620 | 641 | | |
621 | 642 | | |
622 | 643 | | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
623 | 649 | | |
624 | 650 | | |
625 | 651 | | |
| |||
630 | 656 | | |
631 | 657 | | |
632 | 658 | | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
648 | 669 | | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | 670 | | |
654 | 671 | | |
655 | 672 | | |
| |||
0 commit comments