`ZipFile.mkdir()` corrupts archives during an active write
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 30/100
Direzione di ricerca
Inizia in Lib/zipfile/init.py da ZipFile.mkdir e confronta la sua gestione degli handle dei membri scrivibili attivi con open(..., mode="w"), write(), writestr() e close(). Esegui il riproduttore minimo; il completamento significa che mkdir rifiuta l'operazione con un ValueError prima di modificare l'archivio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug description:
Summary
ZipFile.mkdir() does not reject calls made while another writable member handle returned by ZipFile.open(..., mode="w") is active. On seekable output,mkdir() seeks back to the current central-directory start and writes a new local header there. This overwrites or aliases the active member's local header and can produce a corrupt ZIP archive without raising an exception.
Minimal Reproducer
import io
import zipfile
buffer = io.BytesIO()
zf = zipfile.ZipFile(buffer, "w")
member = zf.open("file.txt", mode="w")
zf.mkdir("directory") # Should reject this operation
member.write(b"payload")
member.close()
zf.close()
with zipfile.ZipFile(io.BytesIO(buffer.getvalue())) as broken:
print(broken.namelist())
print(broken.read("directory/"))
Observed behavior:
['directory/', 'file.txt']
Traceback (most recent call last):
File "/home/ubuntu/cpython-main/test.py", line 15, in <module>
print(broken.read("directory/"))
~~~~~~~~~~~^^^^^^^^^^^^^^
File "/home/ubuntu/cpython-main/Lib/zipfile/__init__.py", line 2165, in read
with self.open(name, "r", pwd) as fp:
~~~~~~~~~^^^^^^^^^^^^^^^^
File "/home/ubuntu/cpython-main/Lib/zipfile/__init__.py", line 2239, in open
raise BadZipFile(
'File name in directory %r and header %r differ.'
% (zinfo.orig_filename, fname))
zipfile.BadZipFile: File name in directory 'directory/' and header b'file.txt' differ.
The exact error may vary with the archive contents, but the resulting archive is structurally inconsistent.
Expected Behavior
mkdir() should reject the operation before changing the archive, consistent with the existing behavior of open(..., mode="w"), write(), writestr(), and close() when a writable member handle is active. A ValueError with a message explaining that another write handle is open would be appropriate.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-156079
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Merge medio
- 1g 9h
- PR unite (30g)
- 558
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/cpython
-
docs pending
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
stdlib type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
build type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
stdlib topic-email type-feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Tutte le issue di python/cpython
Issue simili
-
link-check link-check:sphinx-theme
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
OpenHands/extensions#626 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
CSCfi/sd-search-api#39 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100