Improper sanitization and documentation for `ZipFile.mkdir(mode)`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug report
Bug description:
When calling ZipFile.mkdir(), the user provided mode does not have the file format bits cleared, which may cause the created entry be recognized as an incorrect or unknown file format.
import io
import stat
import zipfile
with zipfile.ZipFile(io.BytesIO(), 'w') as zh:
zh.mkdir('foo/', 0o107777) # regular file
zinfo = zh.getinfo('foo/')
print(oct(stat.S_IFMT(zinfo.external_attr >> 16))) # 0o140000 (socket file)
with zipfile.ZipFile(io.BytesIO(), 'w') as zh:
zh.mkdir('foo/', 0o127777) # symbolic link
zinfo = zh.getinfo('foo/')
print(oct(stat.S_IFMT(zinfo.external_attr >> 16))) # 0o160000 (unknown)
Additionally, the current source code and doc for ZipFile.mkdir()'s default mode value are 511, which is identical to 0o777 but less intuitive.
Suggestion
Instead of the current sanitization:
zinfo.external_attr = ((0o40000 | mode) & 0xFFFF) << 16
we should probably sanitize the provided mode as what stat.S_IMODE does, i.e.:
zinfo.external_attr = (0o40000 | (mode & 0o7777)) << 16
We should probably also revise the source code and doc for ZipFile.mkdir()'s default mode value to 0o777, to be consistent with os.mkdir() and more intuitive.
CPython versions tested on:
3.14
Operating systems tested on:
No response
Linked PRs
- gh-154509
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne beim Einstiegspunkt ZipFile.mkdir() und untersuche, wie mode in external_attr bereinigt wird, zusammen mit dem dokumentierten Standardwert. Vergleiche das Verhalten mit stat.S_IMODE und os.mkdir(); abgeschlossen ist die Arbeit, wenn Bits für Dateitypen ausgeschlossen sind und der Standardwert als 0o777 angezeigt wird, wobei der verknüpfte PR gh-154509 auf bereits laufende Arbeiten geprüft wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- operating-systems
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 25/100