>> ...">

zipfile.Path regression · Issue #123270 · python/cpython (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@obfusk

Description

@obfusk

Bug report

Bug description:

#122906 introduced a regression with directories that look like Windows drive letters (on Linux):

import io, zipfile zf = zipfile.ZipFile(io.BytesIO(), "w") zf.writestr("d:/foo", "bar") zf.extractall("a") open("a/d:/foo").read() 'bar' p = zipfile.Path(zf) x = p / "d" / "foo" y = p / "d:" / "foo" list(p.iterdir()) # before: [Path(None, 'd:/')] [Path(None, 'd/')] p.root.namelist() # before: ['d:/foo', 'd:/'] ['d/foo', 'd/'] x.exists() # before: False True y.exists() # before: True False zf.extractall("b") # before: worked like above KeyError: "There is no item named 'd/foo' in the archive" x.read_text() # before: FileNotFoundError KeyError: "There is no item named 'd/foo' in the archive" y.read_text() # before: worked FileNotFoundError: ...

This is the result of _sanitize() unconditionally treating a directory that looks like a drive letter as such and removing the colon, regardless of operating system:

bare = re.sub('^([A-Z]):', r'\1', name, flags=re.IGNORECASE)

Whereas _extract_member() uses os.path.splitdrive() (which is a no-op on Linux):

arcname = os.path.splitdrive(arcname)[1]

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs