Repository navigation
Incorrect use of PyObject_IsInstance #68445
Description
Activity
PyObject_IsInstance() is used incorrectly for testing if Python object is an instance of specified builtin type before direct access to internals of object. This is not correct, because PyObject_IsInstance() checks the __class__ attribute that can be modified and even can be dynamic property. Correct way is to check static type. Proposed patch replaces PyObject_IsInstance() with PyObject_TypeCheck() if this is appropriate.
- addedextension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
on May 21, 2015 Is there any chance that these changes will break working code, or is it the case that if the current check passes incorrectly one will always get a segfauilt or other error?
is it the case that if the current check passes incorrectly
one will always get a segfauilt or other error?Yes, that is the case. All four of these checks precede a reference to an structure member that depends on being an exact type or subtype. So, yes they are all necessary to prevent segfaults or other undefined behavior.
Yes, it is the case that if the current check passes incorrectly one will always get a segfauilt or other error.
Added tests for types.SimpleNamespace and sqlite3.Cursor. It is not easy to reproduce a bug for StopIterator (not sure it is reproducible), but the code looks definitely erroneous in any case.
Serhiy, go ahead and apply your patch. The existing code is clearly wrong.
New changeset bccaba8a5482 by Serhiy Storchaka in branch '2.7':
Issue bpo-24257: Fixed segmentation fault in sqlite3.Row constructor with faked
https://hg.python.org/cpython/rev/bccaba8a5482New changeset c7b9645a6f35 by Serhiy Storchaka in branch '3.4':
Issue bpo-24257: Fixed incorrect uses of PyObject_IsInstance().
https://hg.python.org/cpython/rev/c7b9645a6f35New changeset a5101529a8a9 by Serhiy Storchaka in branch 'default':
Issue bpo-24257: Fixed incorrect uses of PyObject_IsInstance().
https://hg.python.org/cpython/rev/a5101529a8a9
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:
bugs.python.org fields: