This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Check if PyObject_Size() raised an error
Type: crash Stage: resolved
Components: Extension Modules, Interpreter Core, IO Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: rhettinger, serhiy.storchaka, xiang.zhang
Priority: normal Keywords:

Created on 2017-04-12 20:58 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1096 merged serhiy.storchaka, 2017-04-12 21:14
PR 1131 serhiy.storchaka, 2017-04-17 09:56
PR 1180 merged serhiy.storchaka, 2017-04-19 17:34
PR 1182 merged serhiy.storchaka, 2017-04-19 18:34
PR 1183 merged serhiy.storchaka, 2017-04-19 18:48
Messages (6)
msg291573 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-12 20:58
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):
  File "<stdin>", line 1 in <module>
msg291642 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-14 07:36
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?
msg291888 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-19 17:03
New changeset bf623ae8843dc30b28c574bec8d29fc14be59d86 by Serhiy Storchaka in branch 'master':
bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (#1096)
https://github.com/python/cpython/commit/bf623ae8843dc30b28c574bec8d29fc14be59d86
msg291894 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-19 18:22
New changeset 680fea4067537a9b9c79aadd44a3a19e83cd2dbf by Serhiy Storchaka in branch '3.6':
bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (#1096) (#1180)
https://github.com/python/cpython/commit/680fea4067537a9b9c79aadd44a3a19e83cd2dbf
msg291896 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-19 19:09
New changeset e63af29c87b44bb7ada5783cd0ff6ee6d4f9c17c by Serhiy Storchaka in branch '3.5':
[3.5] bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (GH-1096) (GH-1180) (#1182)
https://github.com/python/cpython/commit/e63af29c87b44bb7ada5783cd0ff6ee6d4f9c17c
msg291898 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-19 19:35
New changeset 64aa4df8502ca5d0a8ffb767ff97f625625c758c by Serhiy Storchaka in branch '2.7':
[2.7] bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (GH-1096) (GH-1180) (#1183)
https://github.com/python/cpython/commit/64aa4df8502ca5d0a8ffb767ff97f625625c758c
History
Date User Action Args
2022-04-11 14:58:45adminsetgithub: 74247
2017-04-19 19:36:45serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-04-19 19:35:01serhiy.storchakasetmessages: + msg291898
2017-04-19 19:09:58serhiy.storchakasetmessages: + msg291896
2017-04-19 18:48:32serhiy.storchakasetpull_requests: + pull_request1312
2017-04-19 18:34:45serhiy.storchakasetpull_requests: + pull_request1311
2017-04-19 18:22:51serhiy.storchakasetmessages: + msg291894
2017-04-19 17:34:01serhiy.storchakasetpull_requests: + pull_request1308
2017-04-19 17:03:54serhiy.storchakasetmessages: + msg291888
2017-04-19 15:46:55serhiy.storchakasetassignee: serhiy.storchaka
2017-04-17 09:56:09serhiy.storchakasetpull_requests: + pull_request1294
2017-04-14 07:36:29serhiy.storchakasetnosy: + rhettinger
messages: + msg291642
2017-04-14 05:54:23xiang.zhangsetnosy: + xiang.zhang
2017-04-12 21:15:17serhiy.storchakasetstage: patch review
2017-04-12 21:14:54serhiy.storchakasetpull_requests: + pull_request1239
2017-04-12 20:58:52serhiy.storchakacreate