Title: iter `__reduce__` can segfault if accessing `__builtins__.__dict__['iter']` mutates the iter object · Issue #101765 · python/cpython · GitHub
Open Graph Title: iter `__reduce__` can segfault if accessing `__builtins__.__dict__['iter']` mutates the iter object · Issue #101765 · python/cpython
X Title: iter `__reduce__` can segfault if accessing `__builtins__.__dict__['iter']` mutates the iter object · Issue #101765 · python/cpython
Description: Crash report Example from @chilaxan corrupt = iter(lambda:0, 0) class Cstr: def __hash__(self): return hash('iter') def __eq__(self, other): [*corrupt] return other == 'iter' builtins = __builtins__.__dict__ if hasattr(__builtins__, '__d...
Open Graph Description: Crash report Example from @chilaxan corrupt = iter(lambda:0, 0) class Cstr: def __hash__(self): return hash('iter') def __eq__(self, other): [*corrupt] return other == 'iter' builtins = __builtins_...
X Description: Crash report Example from @chilaxan corrupt = iter(lambda:0, 0) class Cstr: def __hash__(self): return hash('iter') def __eq__(self, other): [*corrupt] return other == 'iter' builti...
Opengraph URL: https://github.com/python/cpython/issues/101765
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"iter `__reduce__` can segfault if accessing `__builtins__.__dict__['iter']` mutates the iter object","articleBody":"# Crash report\r\n\r\nExample from @chilaxan\r\n```python\r\ncorrupt = iter(lambda:0, 0)\r\n\r\nclass Cstr:\r\n def __hash__(self):\r\n return hash('iter')\r\n def __eq__(self, other):\r\n [*corrupt]\r\n return other == 'iter'\r\n\r\nbuiltins = __builtins__.__dict__ if hasattr(__builtins__, '__dict__') else __builtins__\r\noiter = builtins['iter']\r\ndel builtins['iter']\r\nbuiltins[Cstr()] = oiter\r\n\r\nprint(corrupt.__reduce__())\r\n```\r\n\r\n# Expected result\r\nThis should return a valid `__reduce__` tuple of the exhausted iterator. Instead behavior is inconsistent between segmentation faults, SystemErrors, and sometimes returning the iterator without being exhausted.\r\n\r\n# Error messages\r\n\r\n- 3.11, windows, `PYTHONMALLOC=debug`\r\n- 3.12.0a4, windows, `PYTHONMALLOC=debug`\r\n```py\r\nWindows fatal exception: access violation\r\n\u003e exit code -1073741819 (0xC0000005)\r\n```\r\n\r\n- 3.12.04a4, windows, compiled with debug mode\r\n```py\r\n print(corrupt.__reduce__())\r\n ^^^^^^^^^^^^^^^^^^^^\r\nSystemError: NULL object passed to Py_BuildValue\r\n```\r\n\r\n- 3.11, ubuntu\r\n```py\r\n(\u003cbuilt-in function iter\u003e, (\u003cfunction at 0x7fb772c3c4a0\u003e, 0))\r\n\u003e terminated by signal SIGSEGV (Address boundary error)\r\n```\r\n- 3.12.0a4, ubuntu\r\n```py\r\n(\u003cbuilt-in function iter\u003e, (\u003cfunction at 0x7f3480d71f80\u003e, 0))\r\n```\r\n- 3.12.0a4, ubuntu, `PYTHONMALLOC=debug`\r\n```py\r\nFatal Python error: Segmentation fault\r\n```\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-101769\n* gh-102228\n* gh-102229\n* gh-102265\n* gh-102268\n* gh-102269\n* gh-102283\n* gh-102285\n* gh-102286\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ionite34","@type":"Person","name":"ionite34"},"datePublished":"2023-02-09T22:04:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/101765/cpython/issues/101765"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bc75b99a-7285-cea1-85ef-870075c6f54c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D5EC:3960C0:C83B7:11B5A3:696A0279 |
| html-safe-nonce | d7d47fef2f6adc7f13226742c73eca8784b2aa2855673f8b122c71e9c6a03cd4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUVDOjM5NjBDMDpDODNCNzoxMUI1QTM6Njk2QTAyNzkiLCJ2aXNpdG9yX2lkIjoiMzEzOTU0NjM1ODQxODYzNzQzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 67435de207ec3000b09519694c16edb52cfd0aa0d09534f04fa053142e429f1c |
| hovercard-subject-tag | issue:1578682175 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/101765/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53bf50340ff3052ae03548f55988e91c3fdf6896cb197028b82ff23862a896ee/python/cpython/issues/101765 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53bf50340ff3052ae03548f55988e91c3fdf6896cb197028b82ff23862a896ee/python/cpython/issues/101765 |
| og:image:alt | Crash report Example from @chilaxan corrupt = iter(lambda:0, 0) class Cstr: def __hash__(self): return hash('iter') def __eq__(self, other): [*corrupt] return other == 'iter' builtins = __builtins_... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ionite34 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 578c119ff0247c8b2f2491fbf4fc0395cdf909d4df66598cebdc96ddfc4418dc |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 671c2f67171dbced24284331f3133a613d08c366 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width