classification
Title: Updating zip comment doesn't truncate the zip file
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: mzr, nergall2, serhiy.storchaka, twouters
Priority: normal Keywords: patch

Created on 2020-03-29 20:48 by nergall2, last changed 2020-05-22 20:13 by cheryl.sabella.

Pull Requests
URL Status Linked Edit
PR 19333 open nergall2, 2020-04-03 15:20
PR 19337 open mzr, 2020-04-03 16:08
Messages (1)
msg365278 - (view) Author: (nergall2) * 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!
History
Date User Action Args
2020-05-22 20:13:10cheryl.sabellasetnosy: + twouters, serhiy.storchaka
2020-04-03 16:08:10mzrsetpull_requests: + pull_request18700
2020-04-03 15:20:38nergall2setkeywords: + patch
stage: patch review
pull_requests: + pull_request18698
2020-04-03 14:59:12mzrsetnosy: + mzr
2020-03-29 20:48:23nergall2create