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 Oren Milman
Recipients Oren Milman
Date 2017-09-20.13:33:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The following code causes the interpreter to crash (in case '' exists):

import zipimport
zipimport._zip_directory_cache[''] = None
importer = zipimport.zipimporter('')

This is because zipimport_zipimporter___init___impl() (in Modules/zipimport.c)
looks for the zipfile in _zip_directory_cache, and in case it is found, stores
its item in the new ZipImporter. Later, check_is_directory() assumes the stored
item is a dictionary, and passes it to PyDict_Contains(), which crashes.

Similarly, the following code causes a 'SystemError: new style getargs format
but argument is not a tuple':

import zipimport
importer = zipimport.zipimporter('')
zipimport._zip_directory_cache['']['foo\\'] = None

The same would happen if we replace the last line with
"importer.get_data('foo\\')" or "importer.get_source('foo')".

This is because various parts of the code assume that the zipfile's item in
_zip_directory_cache is a dictionary, and that the module's item in this
dictionary is a tuple, which is eventually passed to get_data(), which passes
it to PyArg_ParseTuple(), which raises the SystemError.

Actually, I should have found this as part of #28261. ISTM that the fix for
this issue can easily also fix the issue described in #28261, by checking in
get_data() whether toc_entry is an 8-tuple.

Also, PyDict_GetItem() suppresses all errors, so in some places, e.g. in 
get_module_info(), a bad _zip_directory_cache would probably just be ignored.
But ISTM that we should raise an error saying 'invalid _zip_directory_cache'
in any place where _zip_directory_cache is accessed (in case it is invalid).

What do you think?
Date User Action Args
2017-09-20 13:33:29Oren Milmansetrecipients: + Oren Milman
2017-09-20 13:33:29Oren Milmansetmessageid: <>
2017-09-20 13:33:29Oren Milmanlinkissue31531 messages
2017-09-20 13:33:29Oren Milmancreate