I see. Thanks for the clarification!


On 05/9, 2018, at 22:54, Donald Stufft <donald@stufft.io> wrote:



On Sep 5, 2018, at 9:30 AM, Tzu-ping Chung <uranusjr@gmail.com> wrote:

Isn’t zlib only required for compression? It is my impression that zipfile’s decompressor is pure Python,
and only depends on zlib if the archive is encrypted (but wheels are never encrypted).

zlib also does not provide decompression at its core; for that you need zlib/contrib/minizip, but I don’t
think CPython depends on minizip either.

zlib is technically optional, and not even required to installed wheels.




I don’t think that’s accurate, if you look at zipfile.py, it does: 

https://github.com/python/cpython/blob/874809ea389e6434787e773a6054a08e0b81f734/Lib/zipfile.py#L17-L22

Which attempts to import the zlib module, and if it fails sets zlib to None. Then later one this is used:

https://github.com/python/cpython/blob/874809ea389e6434787e773a6054a08e0b81f734/Lib/zipfile.py#L682-L683

Which doesn’t guard the expression at all, so I believe if you attempt to unzip a wheel that uses ZIP_STORED without the zlib module built, then you’ll get an AttributeError, None type does not have decompressobj exception.


The Python stdlib zlib module does not appear to have any fallback at all if the zlib library is not available and a recent enough version.