python / python/cpython

Files with ASCII filename and UTF-8 comment lost EFS flag when writing with `zipfile`

Open
#152,845 1 comment 0 reactions 1 assignee View on GitHub

@serhiy-storchaka is already working on this.

Since Jul 2, 2026.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

According to the spec, the EFS flag enforces the filename and comment of a file entry to be UTF-8.

However, the EFS flag is not set when a file with ASCII filename and UTF-8 comment is written through zipfile. This renders its comment at risk of mis-decoding.

Similarly, a file with ASCII filename loses its EFS flag when the central directory is rewritten in append mode. This causes an unexpected metadata mutation and introduces a structural inconsistency between the immutable Local File Header (LFH) and the rewritten Central Directory Entry (CDE). This is also a regression of gh-84353/gh-150091, before which the EFS flag was not altered.

Additionally, the metadata_encoding parameter cannot be specified when an archive is opened with 'a' mode, disallowing a proper decoding with a customized codec.

CPython versions tested on:

3.14, 3.16

Operating systems tested on:

No response

Linked PRs
  • gh-152846

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.