This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ZipFile.read() cannot decrypt multiple members from Windows 7zFM
Type: behavior Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: era, serhiy.storchaka
Priority: normal Keywords:

Created on 2015-06-11 13:53 by era, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
hello.zip era, 2015-06-11 13:53 Simple encrypted 7z archive with two members, password hello
Messages (3)
msg245165 - (view) Author: (era) Date: 2015-06-11 13:53
The attached archive from the Windows version of the 7z file manager (7zFM version 9.20) cannot be decrypted into memory.  The first file succeeds, but the second one fails.

The following small program is able to unzip other encrypted zip archives (tried one created by Linux 7z version 9.04 on Debian from the package p7zip-full, and one from plain zip 3.0-3 which comes from the InfoZip distribution, as well as a number of archives of unknown provenance) but fails on the attached one.

from zipfile import ZipFile
from sys import argv

container = ZipFile(argv[1])
for member in container.namelist():
    print("member %s" % member)
    try:
        extracted = container.read(member)
        print("extracted %s" % repr(extracted)[0:64])
    except RuntimeError, err:
        extracted = container.read(member, 'hello')
        container.setpassword('hello')
        print("extracted with password 'hello': %s" % repr(extracted)[0:64])

Here is the output and backtrace:

member hello/
extracted ''
member hello/goodbye.txt
Traceback (most recent call last):
  File "./nst.py", line 13, in <module>
    extracted = container.read(member, 'hello')
  File "/usr/lib/python2.6/zipfile.py", line 834, in read
    return self.open(name, "r", pwd).read()
  File "/usr/lib/python2.6/zipfile.py", line 901, in open
    raise RuntimeError("Bad password for file", name)
RuntimeError: ('Bad password for file', 'hello/goodbye.txt')

The 7z command is able to extract it just fine:

$ 7z -phello x /tmp/hello.zip

7-Zip 9.04 beta  Copyright (c) 1999-2009 Igor Pavlov  2009-05-30
p7zip Version 9.04 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,1 CPU)

Processing archive: /tmp/hello.zip

Extracting  hello
Extracting  hello/goodbye.txt
Extracting  hello/hello.txt

Everything is Ok

Folders: 1
Files: 2
Size:       15
Compressed: 560
msg245166 - (view) Author: (era) Date: 2015-06-11 14:00
The call to .setpassword() doesn't seem to make any difference.  I was hoping it would offer a workaround, but it didn't.
msg245167 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-06-11 14:29
The file looks not conforming ZIP file specification.

The 12th byte of an encryption header doesn't match the MSB of the CRC, therefore the error. And even ignoring it, compression type 99 is not supported by the zipfile module and even is not mentioned in the specification.

With what command this archive was created?
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68618
2019-10-27 10:22:07serhiy.storchakasetstatus: open -> closed
resolution: not a bug
stage: resolved
2015-06-11 14:29:22serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg245167
2015-06-11 14:00:09erasetmessages: + msg245166
2015-06-11 13:54:33erasettype: behavior
components: + Library (Lib)
title: ZipFile.read() cannot decrypt multiple members from Windows 7zfm -> ZipFile.read() cannot decrypt multiple members from Windows 7zFM
2015-06-11 13:53:41eracreate