New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check if PyObject_Size() raised an error #74247
Comments
PyObject_Size(), PySequence_Size() and PyMapping_Size() can raise an exception. But not always this is checked after using them. This can lead to a crash. For example: >>> import io
>>> class R(io.IOBase):
... def readline(self): return None
...
>>> next(R())
Fatal Python error: a function returned a result with an error set
TypeError: object of type 'NoneType' has no len()
The above exception was the direct cause of the following exception: SystemError: <built-in function next> returned a result with an error set Current thread 0xb749c700 (most recent call first): |
Raymond, could you please look at the change in Objects/setobject.c? It makes the code slightly faster (by avoiding few function calls: PyObject_Size(), PySequence_Size()/PyMapping_Size() and sq_length/mp_length), but the main purpose is making clear that no error check is needed after calling PyObject_Size(). I'm not going to include this change in backports. Xiang suggests larger change that allows to gets rid of one PyDict_CheckExact(). What do you prefer? |
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:
The text was updated successfully, but these errors were encountered: