Issue 36088: zipfile cannot handle zip in zip

Issue36088

Created on 2019-02-23 02:17 by liyugong, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
a.zip liyugong, 2019-02-23 05:26
a.tar liyugong, 2019-02-23 05:28
Messages (5)
msg336356 - (view) Author: Liyu Gong (liyugong) Date: 2019-02-23 02:17
Suppose a.zip is z zip file containing 'abc/def/1.txt'

zf = zipfile.ZipFile('a.zip')
memf = zf.open('abc/def/1.txt', 'r')
zf2 = zipfile.ZipFile(memf) 

will raise an error. However, when a.zip is a tar file containing 'abc/def/1.txt', the following codes

tf = tarfile.open('a.zip')
memf = tf.open('abc/def/1.txt', 'r')
zf2 = zipfile.ZipFile(memf) 

works well. Is it a known issue?

Thanks!
msg336361 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-02-23 05:10
The current behavior looks correct to me. abc/def/1.txt is not a ZIP file, so the error is expected.

tarfile.open('a.zip') raises an error too, because a.zip is not a tar file.
msg336363 - (view) Author: Liyu Gong (liyugong) Date: 2019-02-23 05:26
Sorry, I made a mistake. I retested on the following content

a.zip ==>  abc/def/1.zip

zf = zipfile.ZipFile('a.zip')
memf = zf.open('abc/def/1.zip', 'r')
zf2 = zipfile.ZipFile(memf) 

will raise an error. However, when a.zip is a tar file containing 'abc/def/1.zip', the following codes

a.tar ===> abc/def/1.zip

tf = tarfile.open('a.tar')
memf = tf.extractfile('abc/def/1.zip')
zf2 = zipfile.ZipFile(memf)

works well. 

Since only one file can be uploaded, I will try to upload the tar file on the next post.
msg336364 - (view) Author: Liyu Gong (liyugong) Date: 2019-02-23 05:28
add a.tar
msg336365 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-02-23 05:38
Supporting nested zip files is a new feature added in 3.7 (see issue22908). New features can be added only in new Python versions. 3.6 currently takes only security bug fixes.
History
Date User Action Args
2022-04-11 14:59:11adminsetgithub: 80269
2019-02-23 05:38:06serhiy.storchakasetstatus: open -> closed
resolution: out of date
messages: + msg336365

stage: resolved

2019-02-23 05:28:45liyugongsetfiles: - a.zip
2019-02-23 05:28:32liyugongsetfiles: + a.tar

messages: + msg336364

2019-02-23 05:26:52liyugongsetfiles: + a.zip
status: pending -> open
messages: + msg336363
2019-02-23 05:10:51serhiy.storchakasetstatus: open -> pending
nosy: + serhiy.storchaka
messages: + msg336361
2019-02-23 02:17:51liyugongcreate