[issue31531] crash and SystemError in case of a bad zipimport._zip_directory_cache

2018-09-19 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

zipimport have been rewritten in pure Python (issue25711). All crashes are gone 
with the C code.

--
nosy: +serhiy.storchaka
resolution:  -> out of date
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31531] crash and SystemError in case of a bad zipimport._zip_directory_cache

2017-09-27 Thread Oren Milman

Oren Milman  added the comment:

Yet another code that causes a SystemError:
import zipimport
importer = zipimport.zipimporter('foo.zip')
tup_as_list = 
list(zipimport._zip_directory_cache['foo.zip']['foo\\__init__.py'])
tup_as_list[0] = None
zipimport._zip_directory_cache['foo.zip']['foo\\__init__.py'] = 
tuple(tup_as_list)
importer.load_module('foo')

This could be fixed by checking in get_code_from_data() whether modpath is a 
string.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31531] crash and SystemError in case of a bad zipimport._zip_directory_cache

2017-09-20 Thread Oren Milman

New submission from Oren Milman:

The following code causes the interpreter to crash (in case 'foo.zip' exists):

import zipimport
zipimport._zip_directory_cache['foo.zip'] = None
importer = zipimport.zipimporter('foo.zip')
importer.find_loader('bar')

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('foo.zip')
zipimport._zip_directory_cache['foo.zip']['foo\\__init__.py'] = None
importer.load_module('foo')

The same would happen if we replace the last line with
"importer.get_data('foo\\__init__.py')" 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?

--
components: Extension Modules
messages: 302612
nosy: Oren Milman
priority: normal
severity: normal
status: open
title: crash and SystemError in case of a bad zipimport._zip_directory_cache
type: crash
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com