Title: ZipFile from 'a'ppend-mode file generates invalid zip
Type: behavior Stage:
Components: Library (Lib), Windows Versions: Python 3.6
Status: pending Resolution:
Dependencies: Superseder: Regression in zipfile writing in 2.7.13
View: 29094
Assigned To: Nosy List: BoppreH, paul.moore, serhiy.storchaka, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2017-04-30 01:33 by BoppreH, last changed 2017-06-15 18:30 by serhiy.storchaka.

Messages (2)
msg292616 - (view) Author: (BoppreH) Date: 2017-04-30 01:33
I may be misunderstanding file modes or the `zipfile` library, but

    from zipfile import ZipFile
    ZipFile(open('', 'ab'), 'a').writestr('f.txt', 'z')

unexpectedly creates an invalid zip file. 7zip is able to open and show the file list, but files inside look empty, and Windows simply says it's invalid. 

Changing the file mode from `ab` to `wb+` fixes the problem, but truncates the file, and `rb+` doesn't create the file. Calling `close` on both the `open` and `ZipFile` doesn't help either. Using `ZipFile(...).open` instead of `writestr` has the same problem.

I could only reproduce this on [Windows 10, Python 3.6.1, 64 bit]. The zip file was proper on [Windows 10, Python 3.3.5, 32 bit], [Windows 10 Bash, Python 3.4.3, 64 bit], and [FreeBSD, Python 3.5.3, 64 bit].

This is my first bug report, so forgive me if I made any mistakes.
msg296123 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-15 18:30
This looks a duplicate of issue29094.
Date User Action Args
2017-06-15 18:30:21serhiy.storchakasetstatus: open -> pending
superseder: Regression in zipfile writing in 2.7.13
messages: + msg296123
2017-04-30 11:46:48xiang.zhangsetnosy: + serhiy.storchaka
2017-04-30 01:33:15BoppreHcreate