Skip to content

gh-154174: Support fresh ZipInfo objects in ZipFile.mkdir#154198

Open
zhangli091011 wants to merge 6 commits into
python:mainfrom
zhangli091011:fix/gh-154174-zipfile-mkdir-zipinfo
Open

gh-154174: Support fresh ZipInfo objects in ZipFile.mkdir#154198
zhangli091011 wants to merge 6 commits into
python:mainfrom
zhangli091011:fix/gh-154174-zipfile-mkdir-zipinfo

Conversation

@zhangli091011

@zhangli091011 zhangli091011 commented Jul 19, 2026

Copy link
Copy Markdown

Fixes #154174.

ZipFile.mkdir() expected caller-supplied ZipInfo objects to already have a CRC attribute, even though a fresh ZipInfo does not initialize that attribute.

Initialize CRC, file_size, and compress_size to zero for directory entries regardless of whether mkdir() receives a name or a ZipInfo. Do not apply ZipInfo._for_archive(), since caller-supplied timestamps, compression settings, comments, extra data, and permissions must be preserved consistently with writestr().

Tests verify that a fresh ZipInfo works and that caller metadata is preserved.

Tests:

  • PCbuild\amd64\python_d.exe -m unittest -v test.test_zipfile.test_core.TestWithDirectory.test_mkdir test.test_zipfile.test_core.TestWithDirectory.test_mkdir_zipinfo_preserves_metadata
  • PCbuild\amd64\python_d.exe -m test test_zipfile -v (590 tests passed, 5 skipped)
  • Ruff 0.15.17
  • sphinx-lint 1.0.2
  • git diff --check

AI tooling assisted with repository analysis, implementation, and test preparation. The resulting changes and tests were reviewed and verified against a CPython debug build.

@python-cla-bot

python-cla-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@zhangli091011 zhangli091011 changed the title gh-154174: Fix ZipFile.mkdir with a fresh ZipInfo gh-154174: Support fresh ZipInfo objects in ZipFile.mkdir Jul 20, 2026
Comment thread Lib/zipfile/__init__.py Outdated
Comment thread Lib/zipfile/__init__.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling ZipFile.mkdir() on a new ZipInfo object gets an attribute error

2 participants