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.

Author Matthew Zipay
Recipients Matthew Zipay
Date 2016-01-23.10:41:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The zipfile.ZipInfo.__init__ method permits several of ZipInfo's slot attributes to go uninitialized unless the object is obtained from ZipFile.getinfo() or ZipFile.infolist().

As a result, accessing those attributes (header_offset, CRC, compress_size, or file_size) or attempting to repr() a ZipInfo object can fail unexpectedly with AttributeError. (I say "unexpectedly" because ZipInfo.__init__ and its attributes are public/documented, so the attributes ought to be properly initialized regardless of how the object gets created.)

A simple test to illustrate:

>>> import zipfile
>>> zinfo = zipfile.ZipInfo()
>>> repr(zinfo)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "********/cpython/Lib/", line 376, in __repr__
    result.append(' file_size=%r' % self.file_size)
AttributeError: file_size

(If you assign zinfo.file_size = None, it next fails on compress_size.)

This problem has been noted before - see issues 3039 and 22217 - but has not been resolved.

Patch including tests is attached.
Date User Action Args
2016-01-23 10:41:53Matthew Zipaysetrecipients: + Matthew Zipay
2016-01-23 10:41:53Matthew Zipaysetmessageid: <>
2016-01-23 10:41:53Matthew Zipaylinkissue26185 messages
2016-01-23 10:41:52Matthew Zipaycreate