Skip to content

zipp 1.2.0.post1: CVE-2024-5569 backport (Python 2.7) - #1

Merged
icanhasmath merged 3 commits into
1.2.0.xfrom
1.2.0.post1-security
Nov 6, 2026
Merged

icanhasmath merged 3 commits into
1.2.0.xfrom
1.2.0.post1-security

Conversation

@icanhasmath

@icanhasmath icanhasmath commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

zipp 1.2.0.post1 — Python 2.7 security release

zipp 1.2.0 is the last zipp that installs on Python 2.7, and the Python 2 curated catalog needs it (virtualenv → importlib-metadata 2.1.3 → zipp). Upstream fixed CVE-2024-5569 only in 3.19.1, which is Python 3 only.

Advisory Severity Status
CVE-2024-5569 / GHSA-jfmj-5v4g-7637 Low (CVSS 3.3) PATCH — backport of jaraco/zipp f89b93f (3.20.1)

Changes

  • 7acd4df, then 495d2dc: fix CVE-2024-5569. A member name starting with more than one slash (//two-slash.txt) sent _ancestry() into an infinite loop, so Path.iterdir(), joinpath, / and exists hung. The fix is upstream's one-line change from f89b93f: the loop stops when the remaining path ends with a separator. Adds upstream's doctest, plus test_malformed_paths, which asserts only that iterdir() returns within 3 s.
  • 16ee293 Release 1.2.0.post1. The version is now static and setuptools_scm is no longer a build requirement, as in py 1.11.0.post1. CHANGES.rst entry.

Validation (Python 2.7.18)

One archive per row:

member name v1.2.0 this PR
/one-slash.txt, //two-slash.txt, ../parent.txt hangs (killed after 20 s) returns at once (../)
V: NMS.flac — V: NMS.flac
a\b.txt — a\b.txt
ok/c.txt — ok/
  • python -m doctest zipp.py: the new _ancestry doctest passes. One doctest already fails on v1.2.0 under Python 2 (u'content of c' repr), untouched here.
  • setup.py sdist produces zipp-1.2.0.post1.tar.gz with Version: 1.2.0.post1.
  • The full test_zipp.py needs unittest2, func_timeout and jaraco.itertools, which the local Python 2 has none of, so I did not run it.

After merge: tag v1.2.0.post1, GitHub release (not latest), inventory zipp 1.2.0.1, override row, and a build into curated-catalog draft py27-forks-20261105.

icanhasmath and others added 2 commits November 6, 2026 11:35
A crafted zip whose member names contain a doubled separator (for
example "//two-slash.txt") sent _ancestry() into an infinite loop:
posixpath.split("//") returns "//" again, which never equals "/" and
never becomes empty. Any Path operation that computes implied
directories (iterdir, joinpath, "/", exists, ...) hung on such a file.
GHSA-jfmj-5v4g-7637.

Backport of jaraco/zipp fd604bd (3.19.1): add a SanitizedNames mixin
that strips drive letters, backslashes, empty, "." and ".." segments
from every name, and mix it into CompleteDirs ahead of ZipFile.

Python 2.7 adaptation: SanitizedNames derives from object and calls
super(SanitizedNames, self) explicitly; doctests compare str() so they
pass on 2.7. Adds test_malformed_paths, which hangs on 1.2.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Static version (setuptools_scm dropped) and changelog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@icanhasmath
icanhasmath marked this pull request as ready for review November 6, 2026 17:36

@ezequielp-activestate ezequielp-activestate left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes: 1 blocker.

🔴 Blockers

1. This ports the CVE-2024-5569 fix that upstream later reverted because it broke valid archives. (zipp.py, SanitizedNames)

  • The upstream history:

    • SanitizedNames shipped in zipp 3.19.1 (fd604bd).
    • Upstream then removed it in 3cb5609 ("Removed SanitizedNames. Restores expectations around special characters in zipfiles"), because it rewrites legitimate member names (python/cpython#123270).
    • The fix that remains in upstream and in CPython is f89b93f (zipp 3.20.1), a one-line change in _ancestry:
      -    while path and path != posixpath.sep:
      +    while path and not path.endswith(posixpath.sep):
  • Reproduced on Python 2.7.18, each archive holding a single member:

    member name 1.2.0 this PR 1.2.0 + f89b93f
    //two-slash.txt (with /one-slash.txt, ../parent.txt) hangs lists one-slash.txt, parent.txt, two-slash.txt returns at once (lists ../)
    V: NMS.flac — iterdir() shows V NMS.flac, a name that isn't in the archive V: NMS.flac
    a\b.txt (backslash is not a separator in zip) — iterdir() shows a phantom directory a/ a\b.txt
    ok/c.txt — ok/ ok/
  • Both fixes stop the hang. But with this PR, Path lists names that don't exist in the archive, while 1.2.0 + f89b93f lists them correctly.

Suggested change:

  • Replace the SanitizedNames mixin with f89b93f's _ancestry change, plus its doctest (list(_ancestry('//b//d///f//'))).
  • Turn test_malformed_paths into a no-hang test, for example list(root.iterdir()) under a timeout. Upstream marks the exact-listing assertion xfail after f89b93f, because the listing of malformed names isn't meaningful.

Checked

  • The SanitizedNames code matches upstream 3.19.1 apart from the Python 2 spellings (object base, explicit super, str() around the doctest calls).
  • The release changes (static version='1.2.0.post1', setuptools_scm dropped from the build requirements) look right.

Not assessed

  • The full test_zipp.py suite.
  • Windows.
Upstream removed SanitizedNames (3cb5609) because it rewrote legitimate
member names (python/cpython#123270): "V: NMS.flac" listed as
"V NMS.flac", and "a\b.txt" grew a phantom "a/" directory. The fix kept
in zipp 3.20.1 and CPython is f89b93f: stop _ancestry when the remaining
path ends with a separator, so "//x" terminates without renaming
anything.

Replace the mixin with that one-line change and its doctest.
test_malformed_paths now asserts only that iterdir() returns within 3s,
since upstream marks the exact listing of malformed names xfail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@icanhasmath

Copy link
Copy Markdown
Collaborator Author

Thanks, you're right. Upstream removed SanitizedNames in 3cb5609, and the fix that stays in 3.20.1 and CPython is f89b93f.

495d2dc replaces the mixin with f89b93f's one-line _ancestry change and its doctest (list(_ancestry('//b//d///f//'))). test_malformed_paths is now a no-hang test: it runs iterdir() under a 3 s func_timeout and doesn't assert the listing.

Re-checked on Python 2.7.18 with your cases: the malformed archive returns at once (lists ../); V: NMS.flac, a\\b.txt and ok/c.txt list as V: NMS.flac, a\\b.txt and ok/. v1.2.0 still hangs on the malformed archive. I updated CHANGES.rst and the PR body to match.

@ezequielp-activestate ezequielp-activestate left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 495d2dc. The blocker is resolved, and nothing else blocks.

🔴 Blockers: None.

What changed: 495d2dc replaces SanitizedNames with upstream's _ancestry fix (f89b93f, zipp 3.20.1), and test_malformed_paths now only checks that iterdir() finishes.

Checked (Python 2.7.18, python:2.7 container)

  • The zipp.py change, code and doctest, is identical to f89b93f. Member names are no longer rewritten.
  • The full test_zipp.py suite (with func_timeout, jaraco.itertools, unittest2 installed):
    • On this branch, all 15 tests pass.
    • With the new test copied onto 1.2.0, only test_malformed_paths errors: FunctionTimedOut ... timed out after 3.000000 seconds. So the test catches the hang.
  • python -m doctest zipp.py: the new _ancestry doctest passes. The one failure (the u'content of c' repr in the Path docstring) also fails on 1.2.0.
  • The names from my earlier review (V: NMS.flac, a\b.txt) list unchanged, as Marc reported.

Not assessed: Windows.

@icanhasmath
icanhasmath merged commit 1ae6976 into 1.2.0.x Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants