You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crash in imputil.imp.find_module when a *directory* exists with the given name due to double-close of FILE* #58274
bpo-7732: imp.find_module crashes Python if there exists a directory named "init.py"
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2012-02-20.20:36:46.322>created_at=<Date2012-02-20.19:01:40.848>labels= ['library', 'type-crash']
title='Crash in imputil.imp.find_module when a *directory* exists with the given name due to double-close of FILE*'updated_at=<Date2012-02-20.20:36:46.321>user='https://github.com/davidmalcolm'
The call fails at the very end of fill_file_fields() inside the call to dircheck() here:
180 f->f_fp = fp;
181 f = dircheck(f);
182 return (PyObject *) f;
183 }
184
but f->fp == fp
Hence when fill_file_fields returns NULL, and f is cleaned up here:
484 if (fill_file_fields(f, fp, o_name, mode, close) == NULL) {
Activity
davidmalcolm commentedon Feb 20, 2012
What's happening is that call_find_module opens fp, and tries to create a PyFileObject from it:
2844 if (fp != NULL) {
The call fails at the very end of fill_file_fields() inside the call to dircheck() here:
180 f->f_fp = fp;
181 f = dircheck(f);
182 return (PyObject *) f;
183 }
184
but f->fp == fp
Hence when fill_file_fields returns NULL, and f is cleaned up here:
484 if (fill_file_fields(f, fp, o_name, mode, close) == NULL) {
then f->fp is closed within file_dealloc()
Then, when PyFile_FromFile returns NULL, call_find_module calls fclose(fp):
2844 if (fp != NULL) {
2845 fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose);
2846 if (fob == NULL) {
and it attempts to close fp for the second time.
The documentation for PyFile_FromFile:
http://docs.python.org/c-api/file.html#PyFile_FromFile
says:
"Return NULL and close the file using close on failure".
It therefore looks like call_find_module's fclose(fp) is incorrect here, and is what leads to the double-free.
davidmalcolm commentedon Feb 20, 2012
Duplicate of bpo-7732