classification
Title: Updating zip comment doesn't truncate the zip file
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, mzr, serhiy.storchaka, taleinat, twouters, yudilevi
Priority: normal Keywords: patch

Created on 2020-03-29 20:48 by yudilevi, last changed 2020-09-28 20:18 by miss-islington. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19333 closed yudilevi, 2020-04-03 15:20
PR 19337 merged mzr, 2020-04-03 16:08
PR 22436 closed miss-islington, 2020-09-28 18:54
PR 22437 merged miss-islington, 2020-09-28 18:54
PR 22439 merged miss-islington, 2020-09-28 19:56
Messages (5)
msg365278 - (view) Author: Yudilevi (yudilevi) * Date: 2020-03-29 20:48
Updating the zip file comment to a shorter comment should truncate the zip file at the end of the new comment.
Instead, the new comment is written to the zip file but the file length stays the same.

For example, for a zip file that has the following zip comment:
b'This is my old amazing comment, I bet you really like it!' # 57 character long

Executing the following code:

zipFile = ZipFile(filePath, 'a')
zipFile.comment = b'My new shorter comment' # 22 character long
zipFile.close()

Will actually update the comment length in the zip header to the correct new length (22), but the bytecode will still have the following data:
b'My new shorter comment comment, I bet you really like it!'

Python reads the comment correctly since it relies on the comment length from the metadata (as far as I can tell), but the file is corrupt.

This is similar to the following old issue -
https://bugs.python.org/issue9239

But I wasn't sure whether to try and re-open that old one or create a new one.

Tested on version 3.8.2 (Windows 10).

Thanks!
msg377614 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-09-28 18:53
New changeset ff9147d93b868f0e13b9fe14e2a76c2879f6787b by Jan Mazur in branch 'master':
bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337)
https://github.com/python/cpython/commit/ff9147d93b868f0e13b9fe14e2a76c2879f6787b
msg377615 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-09-28 18:54
Thanks for the report and initial PR, Yudi!

Thanks for the second PR, Jan!
msg377617 - (view) Author: miss-islington (miss-islington) Date: 2020-09-28 19:18
New changeset e4008404fbc0002c49becc565d42e93eca11dd75 by Miss Islington (bot) in branch '3.8':
bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337)
https://github.com/python/cpython/commit/e4008404fbc0002c49becc565d42e93eca11dd75
msg377623 - (view) Author: miss-islington (miss-islington) Date: 2020-09-28 20:18
New changeset 048f54dc75d51e8a1c5822ab7b2828295192aaa5 by Miss Islington (bot) in branch '3.9':
bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337)
https://github.com/python/cpython/commit/048f54dc75d51e8a1c5822ab7b2828295192aaa5
History
Date User Action Args
2020-09-28 20:18:50miss-islingtonsetmessages: + msg377623
2020-09-28 19:56:32miss-islingtonsetpull_requests: + pull_request21468
2020-09-28 19:18:46miss-islingtonsetnosy: + miss-islington
messages: + msg377617
2020-09-28 18:54:57taleinatsetversions: + Python 3.9, Python 3.10
2020-09-28 18:54:51taleinatsetstatus: open -> closed

nosy: - miss-islington
messages: + msg377615

resolution: fixed
stage: patch review -> resolved
2020-09-28 18:54:13miss-islingtonsetpull_requests: + pull_request21467
2020-09-28 18:54:05miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request21466
2020-09-28 18:53:41taleinatsetnosy: + taleinat
messages: + msg377614
2020-05-22 20:13:10cheryl.sabellasetnosy: + twouters, serhiy.storchaka
2020-04-03 16:08:10mzrsetpull_requests: + pull_request18700
2020-04-03 15:20:38yudilevisetkeywords: + patch
stage: patch review
pull_requests: + pull_request18698
2020-04-03 14:59:12mzrsetnosy: + mzr
2020-03-29 20:48:23yudilevicreate