Skip to content

gh-51067: Remove trailing space in _Repacker.repack() error message - #152138

Merged
gpshead merged 1 commit into
python:mainfrom
danny0838:gh-51067-4
Oct 12, 2026
Merged

gpshead merged 1 commit into
python:mainfrom
danny0838:gh-51067-4

Conversation

@danny0838

@danny0838 danny0838 commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Remove an accidental trailing space inside the BadZipFile exception string literal to ensure clean exception messages.

…essage

Remove an accidental trailing space inside the `BadZipFile` exception
string literal to ensure clean exception messages.
@StanFromIreland

Copy link
Copy Markdown
Member

In the future, it's fine to bundle several small clean-ups (like the de-deduplication) in one PR.

@StanFromIreland
StanFromIreland requested a review from gpshead June 25, 2026 11:59
@danny0838

Copy link
Copy Markdown
Contributor Author

@StanFromIreland @gpshead Is there still any major concern about this PR?

FYI, this error was introduced because I forgot to remove the trailing space when copying the code snippet from the zip bomb check:

            if (zinfo._end_offset is not None and
                zef_file.tell() + zinfo.compress_size > zinfo._end_offset):
                if zinfo._end_offset == zinfo.header_offset:
                    import warnings
                    warnings.warn(
                        f"Overlapped entries: {zinfo.orig_filename!r} "
                        f"(possible zip bomb)",
                        skip_file_prefixes=(os.path.dirname(__file__),))
                else:
                    raise BadZipFile(
                        f"Overlapped entries: {zinfo.orig_filename!r} "
                        f"(possible zip bomb)")

I removed the "(possible zip bomb)" because it's irrelevant and may be improper here. The overlapping check here is against all ZipInfos in the ZipFile PLUS all ZipInfos passed by the removed argument for ZipFile.repack. It may happen on a normal ZIP archive when ZipInfos passed by removed are improper.

For example, when calling repack([m1]) and then repack([m2]) for a ZipFile with (m1, m2, m3) and has (m1, m2) removed, because m3 has been repositioned to a smaller offset in the prior repack and therefore overlaps with m2, which still records the original offset and size.

For another example, when calling repack([m1]) for a ZipFile with m1, m2, m3 and m1 is not removed.

We do can consider providing a more comprehensive hint, such as the offset or used size of the offensive member, but it may need much more considerations and I think we can do the clean first and left it to future enhancement.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Oct 11, 2026
@gpshead gpshead added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 12, 2026
@gpshead
gpshead merged commit aab474a into python:main Oct 12, 2026
104 of 106 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @danny0838 for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @danny0838 and @gpshead, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker aab474a35b7d47aa3404db0fd5cb2c0314090941 3.15

@miss-islington-app

Copy link
Copy Markdown

Sorry, @danny0838 and @gpshead, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker aab474a35b7d47aa3404db0fd5cb2c0314090941 3.14

@gpshead gpshead removed needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants