Commit 130e1dd
committed
gh-156434: Restore entry offsets when
_ZipRepacker.repack() updates ZipInfo.header_offset for each member
before moving that member's bytes, so a failing _copy_bytes() left the
in-memory offsets describing a layout that was never written. remove()
has already set _didModify, so a later close() committed a central
directory built from those offsets, and the archive became unreadable
even though the caller had handled the error.
ZipFile.repack() now snapshots the offsets of the surviving and the
removed entries and restores them if the repack raises. The copy only
ever moves data to lower offsets, so a partial move never overwrites
its own source and the archive falls back to the state of a remove()
with no repack().repack() fails1 parent fe3a26f commit 130e1dd
2 files changed
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2662 | 2662 | | |
2663 | 2663 | | |
2664 | 2664 | | |
| 2665 | + | |
| 2666 | + | |
| 2667 | + | |
| 2668 | + | |
| 2669 | + | |
| 2670 | + | |
| 2671 | + | |
| 2672 | + | |
| 2673 | + | |
| 2674 | + | |
| 2675 | + | |
| 2676 | + | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
2665 | 2708 | | |
2666 | 2709 | | |
2667 | 2710 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2434 | 2434 | | |
2435 | 2435 | | |
2436 | 2436 | | |
| 2437 | + | |
| 2438 | + | |
2437 | 2439 | | |
2438 | 2440 | | |
2439 | 2441 | | |
2440 | 2442 | | |
2441 | 2443 | | |
2442 | 2444 | | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
2443 | 2449 | | |
2444 | 2450 | | |
2445 | 2451 | | |
| |||
0 commit comments