classification
Title: _imp.load_dynamic() does crash with non-ASCII path and uses the wrong encoding
Type: crash Stage: resolved
Components: Tkinter Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, loewis, python-dev, vstinner
Priority: normal Keywords: patch

Created on 2012-08-22 15:41 by vstinner, last changed 2012-10-01 22:59 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
imp.patch vstinner, 2012-08-22 15:41 review
Messages (4)
msg168892 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-08-22 15:41
_imp.load_dynamic() use UTF-8 (PyUnicode_FromString) to decode the error message from dlerror(), whereas the locale encoding should be used. The path is decoded from UTF-8, whereas the filesystem encoding should be used.

As a result, error_ob and path can be NULL, whereas Py_DECREF() is used and so Python does crash (SIGSEGV).

Attached patch should avoid a crash, but I'm not sure that it is enough to support non-ASCII path: pathname is "./" is the path is not an absolute path.

PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname);
  should maybe be replaced with
pathbytes = PyBytes_FromFormat("./%s", pathname);
msg168893 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-08-22 15:46
New changeset eaac55703796 by Victor Stinner in branch 'default':
Issue #15766: Fix a crash in imp.load_dynamic() on PyUnicode_FromString() failure
http://hg.python.org/cpython/rev/eaac55703796
msg168900 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-08-22 17:33
The patch is still insufficient. Any of the functions can fail because of memory exhaustion, so a fix should really use the standard error handling procedure.
msg171755 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-01 22:59
New changeset f3ed5e211fcc by Victor Stinner in branch 'default':
Close #15766: Catch exceptions while raising the ImportError in imp.load_dynamic()
http://hg.python.org/cpython/rev/f3ed5e211fcc
History
Date User Action Args
2012-10-01 22:59:55python-devsetstatus: open -> closed
resolution: fixed
messages: + msg171755

stage: resolved
2012-08-22 17:33:14loewissetnosy: + loewis
messages: + msg168900
2012-08-22 15:46:50python-devsetnosy: + python-dev
messages: + msg168893
2012-08-22 15:41:22vstinnercreate