New submission from Yudi <yudil...@gmail.com>:

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!

----------
components: Library (Lib)
messages: 365278
nosy: yudilevi
priority: normal
severity: normal
status: open
title: Updating zip comment doesn't truncate the zip file
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40105>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to