Repository navigation
zipp 1.2.0.post1: CVE-2024-5569 backport (Python 2.7) - #1
Conversation
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>
ezequielp-activestate
left a comment
There was a problem hiding this comment.
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:
SanitizedNamesshipped 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.txtreturns at once (lists ../)V: NMS.flac— iterdir()showsV NMS.flac, a name that isn't in the archiveV: NMS.flaca\b.txt(backslash is not a separator in zip)— iterdir()shows a phantom directorya/a\b.txtok/c.txt— ok/ok/ -
Both fixes stop the hang. But with this PR,
Pathlists names that don't exist in the archive, while 1.2.0 + f89b93f lists them correctly.
Suggested change:
- Replace the
SanitizedNamesmixin with f89b93f's_ancestrychange, plus its doctest (list(_ancestry('//b//d///f//'))). - Turn
test_malformed_pathsinto a no-hang test, for examplelist(root.iterdir())under a timeout. Upstream marks the exact-listing assertionxfailafter f89b93f, because the listing of malformed names isn't meaningful.
Checked
- The
SanitizedNamescode matches upstream 3.19.1 apart from the Python 2 spellings (objectbase, explicitsuper,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.pysuite. - 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>
|
Thanks, you're right. Upstream removed 495d2dc replaces the mixin with f89b93f's one-line Re-checked on Python 2.7.18 with your cases: the malformed archive returns at once (lists |
ezequielp-activestate
left a comment
There was a problem hiding this comment.
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.pychange, code and doctest, is identical to f89b93f. Member names are no longer rewritten. - The full
test_zipp.pysuite (withfunc_timeout,jaraco.itertools,unittest2installed):- On this branch, all 15 tests pass.
- With the new test copied onto 1.2.0, only
test_malformed_pathserrors:FunctionTimedOut ... timed out after 3.000000 seconds. So the test catches the hang.
python -m doctest zipp.py: the new_ancestrydoctest passes. The one failure (theu'content of c'repr in thePathdocstring) 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.
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.
Changes
//two-slash.txt) sent_ancestry()into an infinite loop, soPath.iterdir(),joinpath,/andexistshung. 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, plustest_malformed_paths, which asserts only thatiterdir()returns within 3 s.SanitizedNamesmixin. Upstream later removed it (3cb5609) because it rewrote valid member names (zipfile.Path regression python/cpython#123270), so 495d2dc replaces it with f89b93f.Validation (Python 2.7.18)
One archive per row:
/one-slash.txt,//two-slash.txt,../parent.txt../)V: NMS.flacV: NMS.flaca\b.txta\b.txtok/c.txtok/python -m doctest zipp.py: the new_ancestrydoctest passes. One doctest already fails on v1.2.0 under Python 2 (u'content of c'repr), untouched here.setup.py sdistproduceszipp-1.2.0.post1.tar.gzwithVersion: 1.2.0.post1.test_zipp.pyneedsunittest2,func_timeoutandjaraco.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), inventoryzipp 1.2.0.1, override row, and a build into curated-catalog draftpy27-forks-20261105.