Title: `SystemError` from `termios.tcsetwinsize`passing `NULL` to `PyLong_AsLong` · Issue #146091 · python/cpython · GitHub
Open Graph Title: `SystemError` from `termios.tcsetwinsize`passing `NULL` to `PyLong_AsLong` · Issue #146091 · python/cpython
X Title: `SystemError` from `termios.tcsetwinsize`passing `NULL` to `PyLong_AsLong` · Issue #146091 · python/cpython
Description: Crash report What happened? It's possible to raise SystemError from termios.tcsetwinsize by passing a sequence that raises on __getitem__ to it. Automated diagnosis: Bug: termios.tcsetwinsize passes NULL to PyLong_AsLong. PySequence_GetI...
Open Graph Description: Crash report What happened? It's possible to raise SystemError from termios.tcsetwinsize by passing a sequence that raises on __getitem__ to it. Automated diagnosis: Bug: termios.tcsetwinsize passe...
X Description: Crash report What happened? It's possible to raise SystemError from termios.tcsetwinsize by passing a sequence that raises on __getitem__ to it. Automated diagnosis: Bug: termios.tcsetwinsize p...
Opengraph URL: https://github.com/python/cpython/issues/146091
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`SystemError` from `termios.tcsetwinsize`passing `NULL` to `PyLong_AsLong`","articleBody":"# Crash report\n\n### What happened?\n\nIt's possible to raise `SystemError` from `termios.tcsetwinsize` by passing a sequence that raises on `__getitem__` to it.\n\n### Automated diagnosis:\n\nBug: `termios.tcsetwinsize` passes `NULL` to `PyLong_AsLong`. `PySequence_GetItem(winsz, 0)` can return `NULL` (e.g., `__getitem__` raises). The result is passed directly to `PyLong_AsLong(NULL)` which calls `PyErr_BadInternalCall()`, masking the real error with `SystemError`.\n\nFile: `Modules/termios.c`, lines 502-510\n\nMRE:\n```python\nimport termios\nimport os\n\nfd = os.open(\"/dev/tty\", os.O_RDWR | os.O_NOCTTY)\n\nclass BadSequence:\n def __len__(self):\n return 2\n def __getitem__(self, idx):\n raise TypeError\n\ntermios.tcsetwinsize(fd, BadSequence())\n```\n\nBacktrace:\n```python\nTraceback (most recent call last):\n File \"/home/danzin/crashers/trigger_termios_null_pylong.py\", line 23, in \u003cmodule\u003e\n termios.tcsetwinsize(fd, BadSequence())\n ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^\nSystemError: Objects/longobject.c:598: bad argument to internal function\n```\nFound using [cpython-review-toolkit](https://github.com/devdanzin/cpython-review-toolkit) with Claude Opus 4.6, using the `/cpython-review-toolkit:explore Modules/termios.c all deep` command.\n\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.15.0a7+ (heads/main:e0f7c1097e1, Mar 17 2026, 18:10:52) [Clang 21.1.2 (2ubuntu6)]\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-146147\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2026-03-17T22:30:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/146091/cpython/issues/146091"}
| 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:0c4b9d8b-9fdb-a985-bd69-b7c5dc431fe4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C6E8:2E11B4:2C9AB1E:3F67CEF:6A51205C |
| html-safe-nonce | 799c44a38d8f89c9ce1dd86680c92c3ff30fc2ad552bcd27e6ecb44b506c00d6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNkU4OjJFMTFCNDoyQzlBQjFFOjNGNjdDRUY6NkE1MTIwNUMiLCJ2aXNpdG9yX2lkIjoiNjkyMTcyMDE2MTU5MTQzNTM1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e9051e65f9edad4208f6546fad31ac3dfd474f17a8995298b78e02b54231463e |
| hovercard-subject-tag | issue:4091530809 |
| 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/146091/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d86aa426d0301587835dd1f285beb32051a88c729c704dc6d75726ff506d8a21/python/cpython/issues/146091 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d86aa426d0301587835dd1f285beb32051a88c729c704dc6d75726ff506d8a21/python/cpython/issues/146091 |
| og:image:alt | Crash report What happened? It's possible to raise SystemError from termios.tcsetwinsize by passing a sequence that raises on __getitem__ to it. Automated diagnosis: Bug: termios.tcsetwinsize passe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devdanzin |
| hostname | github.com |
| expected-hostname | github.com |
| None | 689b683944b0d7f015d0e776452c970832fa81b82dc15284469b556ecced715b |
| 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 | 942b51ed3bd5feee3d5e2719f890a5fe286edbbb |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width