10000 GH-132417: ctypes: Fix potential Py_DECREF(NULL) in py_object handling by NicolasT · Pull Request #132418 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-132417: ctypes: Fix potential Py_DECREF(NULL) in py_object handling #132418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2025

Conversation

NicolasT
Copy link
Contributor
@NicolasT NicolasT commented Apr 11, 2025

@python-cla-bot
Copy link
python-cla-bot bot commented Apr 11, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
bedevere-app bot commented Apr 11, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link
bedevere-app bot commented Apr 11, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link
bedevere-app bot commented Apr 11, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sergey-miryanov
Copy link
Contributor

You don't need to force-push, because all commits will be squashed on merge.

Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
@picnixz
Copy link
Member
picnixz commented Apr 12, 2025

I'll let you apply / reject the suggestions and will merge this by the end of the week. Thanks for the fix!

@picnixz picnixz self-assigned this Apr 12, 2025
@picnixz picnixz enabled auto-merge (squash) April 12, 2025 07:17
@picnixz picnixz added the needs backport to 3.13 bugs and security fixes label Apr 12, 2025
@picnixz picnixz merged commit 2aab2db into python:main Apr 12, 2025
44 checks passed
@miss-islington-app
Copy link

Thanks @NicolasT for the PR, and @picnixz for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 12, 2025
…g functions returning `PyObject *` (pythonGH-132418)

Some functions (such as `PyErr_Occurred`) with a `restype` set to `ctypes.py_object` may return NULL without setting an exception.
(cherry picked from commit 2aab2db)

Co-authored-by: Nicolas Trangez <ikke@nicolast.be>
@bedevere-app
Copy link
bedevere-app bot commented Apr 12, 2025

GH-132425 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Apr 12, 2025
picnixz pushed a commit that referenced this pull request Apr 12, 2025
…ng functions returning `PyObject *` (GH-132418) (#132425)

GH-132417: ctypes: Fix potential `Py_DECREF(NULL)` when handling functions returning `PyObject *` (GH-132418)

Some functions (such as `PyErr_Occurred`) with a `restype` set to `ctypes.py_object` may return NULL without setting an exception.
(cherry picked from commit 2aab2db)

Co-authored-by: Nicolas Trangez <ikke@nicolast.be>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot aarch64 Fedora Stable Refleaks 3.13 (tier-2) has failed when building commit 0aabe44.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1512/builds/499) and take a look at the build logs.
  4. Check if the failure is related to this commit (0aabe44) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1512/builds/499

Failed tests:

  • test_perf_profiler

Failed subtests:

  • test_python_calls_appear_in_the_stack_if_perf_activated - test.test_perf_profiler.TestPerfProfilerWithDwarf.test_python_calls_appear_in_the_stack_if_perf_activated

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/Lib/test/test_perf_profiler.py", line 356, in test_python_calls_appear_in_the_stack_if_perf_activated
    self.assertIn(f"py::foo:{script}", stdout)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'py::foo:/tmp/test_python_jxkdy4ua/tmpqh4bzyvn/perftest.py' not found in 'python  686076 1611040.385357:          1 cycles:Pu: \n\t    ffffb7388ac0 _start+0x0 (/usr/lib/ld-linux-aarch64.so.1)\n\npython  686076 1611040.385386:          1 cycles:Pu: \n\t    ffffb7388ac0 _start+0x0 (/usr/lib/ld-linux-aarch64.so.1)\n\npython  686076 1611040.386148:          1 cycles:Pu: \n\t    ffffb737a308 _dl_relocate_object+0x3a8 (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffffb738644f dl_main+0x164f (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffffb73835ff _dl_sysdep_start+0x1df (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffffb7384b17 _dl_start_final+0x5ab (inlined)\n\t    ffffb7384b17 _dl_start+0x5ab (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffffb7388ad3 _start+0x13 (/usr/lib/ld-linux-aarch64.so.1)\n\npython  686076 1611040.386172:        423 cycles:Pu: \n\t    ffffb73863fc dl_main+0x15fc (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffffb73835ff _dl_sysdep_start+0x1df (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffffb7384b17 _dl_start_final+0x5ab (inlined)\n\t    ffffb7384b17 _dl_start+0x5ab (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffffb7388ad3 _start+0x13 (/usr/lib/ld-linux-aarch64.so.1)\n\npython  686076 1611040.387148:       1072 cycles:Pu: \n\t          67e214 _PyOS_GetOpt+0x30 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          650d67 precmdline_parse_cmdline+0x43 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          651a47 _PyPreCmdline_Read+0xb7 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          651d6f preconfig_read+0x2b (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          6521a3 _PyPreConfig_Read+0x26f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          65b0db _Py_PreInitializeFromPyArgv+0x103 (/
ild/python)\n\t          68b797 Py_BytesMain+0x27 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          41ddb7 main+0xb (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t    ffffb711625b __libc_start_call_main+0x7b (/usr/lib64/libc.so.6)\n\t    ffffb711633b __libc_start_main@@GLIBC_2.34+0x9b (/usr/lib64/libc.so.6)\n\t          41dcaf _start+0x2f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\npython  686076 1611040.388183:     110151 cycles:Pu: \n\t          62f408 _Py_hashtable_set+0x7c (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          55cf53 intern_static+0x83 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          576523 _PyUnicode_InternStatic+0x27 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          57c7d7 _PyUnicode_InitStaticStrings+0x6257 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          58e39f init_global_interned_strings+0x77 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          58e5e7 _PyUnicode_InitGlobalObjects+0x63 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          6534af pycore_init_global_objects+0x23 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          653a57 pycore_interp_init+0x2b (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          653d33 pyinit_config+0xaf (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          65b3ab pyinit_core+0xdb (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          65b483 Py_InitializeFromConfig+0x97 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          68b63f pymain_init+0xff (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          68b703 pymain_main+0xf (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          68b797 Py_BytesMain+0x27 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          41ddb7 main+0xb (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t    ffffb711625b __libc_start_call_main+0x7b (/usr/lib64/libc.so.6)\n\t    ffffb711633b __libc_start_main@@GLIBC_2.34+0x9b (/usr/lib64/libc.so.6)\n\t          41dcaf _start+0x2f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\npython  686076 1611040.390202:    2576198 cycles:Pu: \n\t          50bc8c _PyMem_DebugRawAlloc+0xbc (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          50bcdf _PyMem_DebugRawMalloc+0x17 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          50d2bb _PyMem_DebugMalloc+0x2f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          523007 PyObject_Malloc+0x23 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/b
8000
uild/python)\n\t          55d98b PyUnicode_New+0xab (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          57065f unicode_decode_utf8+0x5f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          570a77 PyUnicode_DecodeUTF8Stateful+0x17 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          570b2f PyUnicode_FromString+0x2b (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          58eb63 PyUnicode_InternFromString+0xb (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          4bb583 descr_new+0x3f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/Lib/test/test_perf_profiler.py", line 356, in test_python_calls_appear_in_the_stack_if_perf_activated
    self.assertIn(f"py::foo:{script}", stdout)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'py::foo:/tmp/test_python_60g3exf1/tmp9jxs7zeb/perftest.py' not found in 'python  788903 1612002.502546:          1 cycles:Pu: \n\t    ffff8c665ac0 _start+0x0 (/usr/lib/ld-linux-aarch64.so.1)\n\npython  788903 1612002.502582:          1 cycles:Pu: \n\tffffaa282d37fc78 [unknown] ([unknown])\n\tffffaa282d38049c [unknown] ([unknown])\n\tffffaa282bf215e4 [unknown] ([unknown])\n\t    ffff8c665ac0 _start+0x0 (/usr/lib/ld-linux-aarch64.so.1)\n\npython  788903 1612002.503089:          1 cycles:Pu: \n\t    ffff8c651ca8 _dl_map_segment+0xfc8 (inlined)\n\t    ffff8c651ca8 _dl_map_segments+0xfc8 (inlined)\n\t    ffff8c651ca8 _dl_map_object_from_fd+0xfc8 (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c652133 _dl_map_object+0x1e7 (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c64d5bf openaux+0x3f (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c64c303 _dl_catch_exception+0x63 (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c64db33 _dl_map_object_deps+0x553 (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c66319f dl_main+0x139f (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c6605ff _dl_sysdep_start+0x1df (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c661b17 _dl_start_final+0x5ab (inlined)\n\t    ffff8c661b17 _dl_start+0x5ab (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c665ad3 _start+0x13 (/usr/lib/ld-linux-aarch64.so.1)\n\npython  788903 1612002.503128:        340 cycles:Pu: \n\tffffaa282d37ff10 [unknown] ([unknown])\n\tffffaa282d3804cc [unknown] ([unknown])\n\tffffaa282bf215e4 [unknown] ([unknown])\n\t    ffff8c66768c mprotect+0xc (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c651057 _dl_map_segments+0x377 (inlined)\n\t    ffff8c651057 _dl_map_object_from_fd+0x377 (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c652133 _dl_map_object+0x1e7 (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c64d5bf openaux+0x3f (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c64c303 _dl_catch_exception+0x63 (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c64db33 _dl_map_object_deps+0x553 (/usr/lib/ld-linux-aarch64.so.1)\n\t    ffff8c66319f dl_main+0x139f (/usr/lib/ld-linux
caf _start+0x2f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\npython  788903 1612002.505311:      72468 cycles:Pu: \n\t    ffff8c45d560 pthread_key_create@@GLIBC_2.34+0x0 (/usr/lib64/libc.so.6)\n\t          678ff3 PyThread_tss_create+0x5b (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          67d623 _PyTraceMalloc_Init+0x3f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          6533bb pycore_create_interpreter+0x207 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          653cf3 pyinit_config+0x6f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          65b3ab pyinit_core+0xdb (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          65b483 Py_InitializeFromConfig+0x97 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          68b63f pymain_init+0xff (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          68b703 pymain_main+0xf (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          68b797 Py_BytesMain+0x27 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          41ddb7 main+0xb (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t    ffff8c3f625b __libc_start_call_main+0x7b (/usr/lib64/libc.so.6)\n\t    ffff8c3f633b __libc_start_main@@GLIBC_2.34+0x9b (/usr/lib64/libc.so.6)\n\t          41dcaf _start+0x2f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\npython  788903 1612002.506553:    1479959 cycles:Pu: \n\t          62f058 _Py_hashtable_get_entry_generic+0x4c (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          62f4a3 _Py_hashtable_get+0xf (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          55d1d7 intern_common+0x11b (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          58eabb _PyUnicode_InternMortal+0x1b (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          58eb77 PyUnicode_InternFromString+0x1f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          4bb583 descr_new+0x3f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          4bc61b PyDescr_NewMethod+0xaf (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          53a29f type_add_method+0x103 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          53a347 type_add_methods+0x2b (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          53a8af type_ready_fill_dict+0x1f (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          5476fb type_ready+0x93 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          54788f init_static_type+0xab (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          547a6f _PyStaticType_InitBuiltin+0x23 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          5077bf _PyTypes_InitTypes+0xa7 (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          65351f pycore_init_types+0x1b (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          653b37 pycore_interp_init+0x10b (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          653d33 pyinit_config+0xaf (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/python)\n\t          65b3ab pyinit_core+0xdb (/home/buildbot/buildarea/3.13.cstratak-fedora-stable-aarch64.refleak/build/py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0