Title: Set: `BUILD_SET` opcode can be failed with segfault · Issue #101952 · python/cpython · GitHub
Open Graph Title: Set: `BUILD_SET` opcode can be failed with segfault · Issue #101952 · python/cpython
X Title: Set: `BUILD_SET` opcode can be failed with segfault · Issue #101952 · python/cpython
Description: cpython/Python/generated_cases.c.h Lines 1648 to 1667 in 36b139a TARGET(BUILD_SET) { PyObject **values = &PEEK(oparg); PyObject *set; set = PySet_New(NULL); int err = 0; for (int i = 0; i < oparg; i++) { PyObject *item = values[i]; if (e...
Open Graph Description: cpython/Python/generated_cases.c.h Lines 1648 to 1667 in 36b139a TARGET(BUILD_SET) { PyObject **values = &PEEK(oparg); PyObject *set; set = PySet_New(NULL); int err = 0; for (int i = 0; i < oparg; ...
X Description: cpython/Python/generated_cases.c.h Lines 1648 to 1667 in 36b139a TARGET(BUILD_SET) { PyObject **values = &PEEK(oparg); PyObject *set; set = PySet_New(NULL); int err = 0; for (int i = 0; i < ...
Opengraph URL: https://github.com/python/cpython/issues/101952
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Set: `BUILD_SET` opcode can be failed with segfault","articleBody":"https://github.com/python/cpython/blob/36b139af638cdeb671cb6b8b0315b254148688f7/Python/generated_cases.c.h#L1648-L1667\r\n\u0026\r\nhttps://github.com/python/cpython/blob/36b139af638cdeb671cb6b8b0315b254148688f7/Python/bytecodes.c#L1303-L1316\r\n\r\nDoesn't take in account case, when `PySet_New(NULL)` returns NULL.\r\nWe are checking that `PySet_Add` doesn't return a non-zero(-1) value.\r\nBut, `PySet_Add` has a check, that first argument is a subclass of `set`. Which fails, if we will pass `(PyObject *) NULL` as first argument. Why?\r\n```c\r\n#define PySet_Check(ob) \\\r\n (Py_IS_TYPE((ob), \u0026PySet_Type) || \\\r\n PyType_IsSubtype(Py_TYPE(ob), \u0026PySet_Type))\r\n```\r\n`PySet_Add` uses this macross. But, `Py_TYPE` will be failed with segfault when try to access `ob_type` of `(PyObject *) NULL`.\r\n\r\nImplementation of `Py_TYPE`:\r\n\r\n```c\r\nstatic inline PyTypeObject* Py_TYPE(PyObject *ob) {\r\n return ob-\u003eob_type;\r\n}\r\n```\r\n\r\n```gdb\r\n(gdb) call (PyObject *) NULL\r\n$1 = (PyObject *) 0x0\r\n(gdb) call $1-\u003eob_type\r\nCannot access memory at address 0x8\r\n```\r\nSo, we should add check, that value of `PySet_New` is not-null.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-101958\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Eclips4","@type":"Person","name":"Eclips4"},"datePublished":"2023-02-16T14:51:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/101952/cpython/issues/101952"}
| 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:a8da5501-874c-a55e-360d-4f07da8a1f11 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C73C:3D0535:17F227E:2027431:6969AB79 |
| html-safe-nonce | 862bd329f534189d286d58d8580593d98e6d5ecc2dad154c2e5d753feea14234 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzNDOjNEMDUzNToxN0YyMjdFOjIwMjc0MzE6Njk2OUFCNzkiLCJ2aXNpdG9yX2lkIjoiNjIzNTA4NTA3MTQwNDYwODM3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8fd1627adc5182ab81e580b2b258587b5070152db8500aa5f30b21740edf5f01 |
| hovercard-subject-tag | issue:1587819369 |
| 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/101952/issue_layout |
| twitter:image | https://opengraph.githubassets.com/96ab4160cfb09e8351a80f293638310e2abfe7fc59e601bde208192340a330e5/python/cpython/issues/101952 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/96ab4160cfb09e8351a80f293638310e2abfe7fc59e601bde208192340a330e5/python/cpython/issues/101952 |
| og:image:alt | cpython/Python/generated_cases.c.h Lines 1648 to 1667 in 36b139a TARGET(BUILD_SET) { PyObject **values = &PEEK(oparg); PyObject *set; set = PySet_New(NULL); int err = 0; for (int i = 0; i < oparg; ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Eclips4 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 24c4c97a2d520cb286b35e1a4c22d7a4df3c26a2fa28dd7cdf0e65db327b4de7 |
| 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 | 124667f43168afb6c9c03b7c02eb5b1d2e1be3d9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width