Title: Instances of subclasses of PyLong_Type created in C extensions use Java object handles, possibly causing segmentation faults · Issue #595 · oracle/graalpython · GitHub
Open Graph Title: Instances of subclasses of PyLong_Type created in C extensions use Java object handles, possibly causing segmentation faults · Issue #595 · oracle/graalpython
X Title: Instances of subclasses of PyLong_Type created in C extensions use Java object handles, possibly causing segmentation faults · Issue #595 · oracle/graalpython
Description: With GraalPy 3.12.8 on Linux, built from source at f466f8d , subclasses of PyLong_Type created using the C API return Java handles from __new__ instead of real PyObject pointers. When an extension attempts to access an instance of the Py...
Open Graph Description: With GraalPy 3.12.8 on Linux, built from source at f466f8d , subclasses of PyLong_Type created using the C API return Java handles from __new__ instead of real PyObject pointers. When an extension ...
X Description: With GraalPy 3.12.8 on Linux, built from source at f466f8d , subclasses of PyLong_Type created using the C API return Java handles from __new__ instead of real PyObject pointers. When an extension ...
Opengraph URL: https://github.com/oracle/graalpython/issues/595
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Instances of subclasses of PyLong_Type created in C extensions use Java object handles, possibly causing segmentation faults","articleBody":"With GraalPy 3.12.8 on Linux, built from source at f466f8d5d9 , subclasses of `PyLong_Type` created using the C API return Java handles from `__new__` instead of real `PyObject` pointers. When an extension attempts to access an instance of the `PyLong_Type` subclass as a `PyObject`, it tries to dereference the Java handle, possibly causing a segmentation fault.\n\nA real example of code that can expose this bug can be seen in `boost::python`'s [`enum.cpp`](https://github.com/boostorg/python/blob/develop/src/object/enum.cpp). In the `enum_base::add_value` method, `boost::python` needs to access the `name` member of the `enum_object` `struct` it uses for the instances of the `enum_type_object`, but this fails on GraalPy. Similarly, the C example extension below attempts to access the `member` member of the `custom_object` `struct` in its `set_member` function.\n\n```c\n/* custom_pyobject.c */\n#define PY_SSIZE_T_CLEAN\n#include \u003cPython.h\u003e\n#include \u003cstddef.h\u003e\n\ntypedef struct custom_object {\n PyLongObject base_object;\n PyObject* member;\n} custom_object;\n\nstatic PyMemberDef custom_members[] = {\n {\"member\", Py_T_OBJECT_EX, offsetof(custom_object, member), Py_READONLY, 0},\n {0, 0, 0, 0, 0}\n};\n\nstatic void custom_dealloc(custom_object* self) {\n Py_XDECREF(self-\u003emember);\n Py_TYPE(self)-\u003etp_free((PyObject*)self);\n}\n\nstatic PyObject* custom_repr(PyObject* self_) {\n custom_object* self = (custom_object*)self_;\n return PyUnicode_FromFormat(\"custom_object(%S)\", PyObject_Repr(self-\u003emember));\n}\n\nstatic PyTypeObject custom_type_object = {\n PyObject_HEAD_INIT(NULL)\n \"custom_object\", /* tp_name */\n sizeof(custom_object), /* tp_basicsize */\n 0, /* tp_itemsize */\n (destructor) custom_dealloc, /* tp_dealloc */\n 0, /* tp_print */\n 0, /* tp_getattr */\n 0, /* tp_setattr */\n 0, /* tp_compare */\n custom_repr, /* tp_repr */\n 0, /* tp_as_number */\n 0, /* tp_as_sequence */\n 0, /* tp_as_mapping */\n 0, /* tp_hash */\n 0, /* tp_call */\n 0, /* tp_str */\n 0, /* tp_getattro */\n 0, /* tp_setattro */\n 0, /* tp_as_buffer */\n Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */\n 0, /* tp_doc */\n 0, /* tp_traverse */\n 0, /* tp_clear */\n 0, /* tp_richcompare */\n 0, /* tp_weaklistoffset */\n 0, /* tp_iter */\n 0, /* tp_iternext */\n 0, /* tp_methods */\n custom_members, /* tp_members */\n 0, /* tp_getset */\n \u0026PyLong_Type, /* tp_base */\n 0, /* tp_dict */\n 0, /* tp_descr_get */\n 0, /* tp_descr_set */\n 0, /* tp_dictoffset */\n 0, /* tp_init */\n 0, /* tp_alloc */\n 0, /* tp_new */\n 0, /* tp_free */\n 0, /* tp_is_gc */\n 0, /* tp_bases */\n 0, /* tp_mro */\n 0, /* tp_cache */\n 0, /* tp_subclasses */\n 0, /* tp_weaklist */\n 0 /* tp_del */\n};\n\nint custom_pyobject_mod_exec(PyObject* module) {\n PyModule_AddType(module, \u0026custom_type_object);\n return 0;\n}\n\nstatic PyModuleDef_Slot custom_pyobject_slots[] = {\n {Py_mod_exec, custom_pyobject_mod_exec},\n {0, NULL}\n};\n\nPyObject* set_member(PyObject* self, PyObject* args) {\n PyObject* inner1;\n PyObject* inner2;\n if (!PyArg_ParseTuple(args, \"OO\", \u0026inner1, \u0026inner2)) {\n return NULL;\n }\n custom_object* obj = (custom_object*)inner1;\n obj-\u003emember = inner2;\n return Py_None;\n}\n\nstatic PyMethodDef custom_pyobject_methods[] = {\n {\"set_member\", set_member, METH_VARARGS, \"Set name.\"},\n {NULL, NULL, 0, NULL}\n};\n\nstatic struct PyModuleDef custom_pyobject_module = {\n .m_base = PyModuleDef_HEAD_INIT,\n .m_name = \"custom_pyobject\",\n .m_size = 0,\n .m_methods = custom_pyobject_methods,\n .m_slots = custom_pyobject_slots\n};\n\nPyMODINIT_FUNC PyInit_custom_pyobject(void) {\n return PyModuleDef_Init(\u0026custom_pyobject_module);\n}\n```\n\nIf the code above is compiled to `custom_pyobject.so`, then the Python code below fails with a segmentation fault on GraalPy:\n\n```python\nimport custom_pyobject\nobj = custom_pyobject.custom_object(10)\ncustom_pyobject.set_member(obj, \"foo\")\nprint(obj)\n```\n\nWith CPython, the code prints `custom_object('foo')`.\n\nThe relevant discussion on Slack can be found at https://graalvm.slack.com/archives/CNA7PDH2N/p1768011927297709 .","author":{"url":"https://github.com/actapia","@type":"Person","name":"actapia"},"datePublished":"2026-01-15T20:54:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/595/graalpython/issues/595"}
| 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:a3ea1fcd-8602-119e-09ec-731ee2b54bc9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 97CA:20D11F:3807B1:4F7857:696F7F5D |
| html-safe-nonce | 2f615b085e14cd984475743426a353cb2d46b85c2c0c5582e381a0559a6347c9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5N0NBOjIwRDExRjozODA3QjE6NEY3ODU3OjY5NkY3RjVEIiwidmlzaXRvcl9pZCI6IjgyMDI3MzUxNzAyNTEzNTgwNDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 56ec84f78921708cfdc65be2d912eb8ff7aeec23c7cd2cfefc1bf1d7c81bc655 |
| hovercard-subject-tag | issue:3819127396 |
| 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/oracle/graalpython/595/issue_layout |
| twitter:image | https://opengraph.githubassets.com/84fe4c1903b5e2f77a997021dbfc0c8dcb436eedc8589154862992933061d191/oracle/graalpython/issues/595 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/84fe4c1903b5e2f77a997021dbfc0c8dcb436eedc8589154862992933061d191/oracle/graalpython/issues/595 |
| og:image:alt | With GraalPy 3.12.8 on Linux, built from source at f466f8d , subclasses of PyLong_Type created using the C API return Java handles from __new__ instead of real PyObject pointers. When an extension ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | actapia |
| hostname | github.com |
| expected-hostname | github.com |
| None | 759c36b32159cc867ba926786bbd5ac69b0804c9cfc86536a67b3567e8bbbb5c |
| turbo-cache-control | no-preview |
| go-import | github.com/oracle/graalpython git https://github.com/oracle/graalpython.git |
| octolytics-dimension-user_id | 4430336 |
| octolytics-dimension-user_login | oracle |
| octolytics-dimension-repository_id | 129883600 |
| octolytics-dimension-repository_nwo | oracle/graalpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 129883600 |
| octolytics-dimension-repository_network_root_nwo | oracle/graalpython |
| 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 | 08632b85cc9aa97742e56978eb25cc43ca37e51b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width