zipfile.BadZipFile thrown instead of openpyxl.utils.exceptions.InvalidFileException upon nonsense data

Issue #631 invalid
Tim Dawborn
created an issue

It seems like a bug that the zipfile.BadFileError is allowed to leak out when passing in nonsense data instead of throwing an InvalidFileException:

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import io
>>> import openpyxl
>>> openpyxl.__version__
u'2.3.3'
>>> openpyxl.load_workbook(io.BytesIO(b'foo'), read_only=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<snip>/ve/local/lib/python2.7/site-packages/openpyxl/reader/excel.py", line 151, in load_workbook
    archive = _validate_archive(filename)
  File "<snip>/ve/local/lib/python2.7/site-packages/openpyxl/reader/excel.py", line 118, in _validate_archive
    archive = ZipFile(f, 'r', ZIP_DEFLATED)
  File "/usr/lib/python2.7/zipfile.py", line 770, in __init__
    self._RealGetContents()
  File "/usr/lib/python2.7/zipfile.py", line 811, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file

Is this a bug or intended behaviour?

Comments (6)

  1. Log in to comment