Skip to content

zipfile.ZipFile fails reading a file object in specific version(s) #70460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
starrify mannequin opened this issue Feb 3, 2016 · 4 comments
Closed

zipfile.ZipFile fails reading a file object in specific version(s) #70460

starrify mannequin opened this issue Feb 3, 2016 · 4 comments
Labels
stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@starrify
Copy link
Mannequin

starrify mannequin commented Feb 3, 2016

BPO 26272
Nosy @vadmium, @starrify

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-02-03.09:03:00.554>
created_at = <Date 2016-02-03.08:48:27.454>
labels = ['library', 'type-crash']
title = '`zipfile.ZipFile` fails reading a file object in specific version(s)'
updated_at = <Date 2016-02-03.09:04:02.366>
user = 'https://github.com/starrify'

bugs.python.org fields:

activity = <Date 2016-02-03.09:04:02.366>
actor = '__starrify__'
assignee = 'none'
closed = True
closed_date = <Date 2016-02-03.09:03:00.554>
closer = '__starrify__'
components = ['Library (Lib)']
creation = <Date 2016-02-03.08:48:27.454>
creator = '__starrify__'
dependencies = []
files = []
hgrepos = []
issue_num = 26272
keywords = []
message_count = 4.0
messages = ['259459', '259461', '259462', '259463']
nosy_count = 2.0
nosy_names = ['martin.panter', '__starrify__']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'closed'
superseder = None
type = 'crash'
url = 'https://bugs.python.org/issue26272'
versions = ['Python 3.5']

@starrify
Copy link
Mannequin Author

starrify mannequin commented Feb 3, 2016

When passing a file object to zipfile.ZipFile for reading it fails in Python 3.5.1 it fails. While the same code in Python 2.7.11 works.
Also loading that specific file directly from file path works in Python 3.5.1.
(Please see the sample testing code below for details)

[pengyu@GLaDOS tmp]$ echo "test message" > testfile
[pengyu@GLaDOS tmp]$ zip testfile.zip testfile
updating: testfile (stored 0%)
[pengyu@GLaDOS tmp]$ file testfile.zip 
testfile.zip: Zip archive data, at least v1.0 to extract
[pengyu@GLaDOS tmp]$ python -c "a = open('testfile.zip'); import zipfile; b = zipfile.ZipFile(a, 'r')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/zipfile.py", line 1026, in __init__
    self._RealGetContents()
  File "/usr/lib/python3.5/zipfile.py", line 1093, in _RealGetContents
    raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file
[pengyu@GLaDOS tmp]$ python2 -c "a = open('testfile.zip'); import zipfile; b = zipfile.ZipFile(a, 'r')"
[pengyu@GLaDOS tmp]$ python -c "import zipfile; b = zipfile.ZipFile('testfile.zip', 'r')"
[pengyu@GLaDOS tmp]$ python --version
Python 3.5.1
[pengyu@GLaDOS tmp]$ python2 --version
Python 2.7.11

@starrify starrify mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Feb 3, 2016
@vadmium
Copy link
Member

vadmium commented Feb 3, 2016

I think you are only meant to pass in a “binary” (bytes) file object. Maybe BufferedIOBase, I’m not sure. The documentation doesn’t seem to make this very clear though. Can you suggest an improvement?

Open the file with

a = open("testfile.zip", "rb")

and all should be well :)

@starrify
Copy link
Mannequin Author

starrify mannequin commented Feb 3, 2016

Well I should have noticed that I wasn't using binary mode.. Sorry for the mistake. Closing the issue report.

@starrify starrify mannequin closed this as completed Feb 3, 2016
@starrify
Copy link
Mannequin Author

starrify mannequin commented Feb 3, 2016

Oh yes you're right Martin. Thanks for the notice :) (I've closed this ticket before seeing your reply)

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

1 participant