Commit Graph

9142 Commits

Author SHA1 Message Date
Miss Islington (bot) 6d6471b7eb [3.13] gh-148418: Fix a possible reference leak in a corrupted TYPE_CODE marshal stream (GH-148419) (GH-149364)
(cherry picked from commit c3972f2795)

Co-authored-by: Wulian233 <1055917385@qq.com>
2026-05-04 14:06:00 +00:00
Irit Katriel 8da3d39c51 [3.13] gh-148973: fix segfault on mismatch between consts size and oparg in compiler (GH-148974) (#148997) 2026-04-25 22:59:40 +01:00
Sam Gross 1b2301c009 [3.13] gh-148820: Fix _PyRawMutex use-after-free on spurious semaphore wakeup (gh-148852) (#148885)
_PyRawMutex_UnlockSlow CAS-removes the waiter from the list and then
calls _PySemaphore_Wakeup, with no handshake. If _PySemaphore_Wait
returns Py_PARK_INTR, the waiter can destroy its stack-allocated
semaphore before the unlocker's Wakeup runs, causing a fatal error from
ReleaseSemaphore / sem_post.

Loop in _PyRawMutex_LockSlow until _PySemaphore_Wait returns Py_PARK_OK,
which is only signalled when a matching Wakeup has been observed.

Also include GetLastError() and the handle in the Windows fatal messages
in _PySemaphore_Init, _PySemaphore_Wait, and _PySemaphore_Wakeup to make
similar races easier to diagnose in the future.

(cherry picked from commit ad3c5b7958)
2026-04-22 18:56:24 +00:00
Serhiy Storchaka ac1c1e7ef0 [3.13] gh-148653: Fix some marshal errors related to recursive code objects (GH-148698) (GH-148711) (GH-148713)
(cherry picked from commit d496c637a3)

Forbid marshalling recursive code objects which
cannot be correctly unmarshalled.
Add multiple tests for recursive data structures.
(cherry picked from commit 2e37d83641)
2026-04-18 09:29:38 +00:00
Hugo van Kemenade 8a0993f500 [3.13] GH-146128: Remove the buggy AArch64 "33rx" relocation (#146263) (#148199)
GH-146128: Remove the buggy AArch64 "33rx" relocation (#146263)

(cherry picked from commit 6bb7b33e8f)

Co-authored-by: Brandt Bucher <brandt@python.org>
Co-authored-by: Ken Jin <kenjin@python.org>
2026-04-07 20:10:33 +02:00
sunmy2019 c0eae2a1c3 [3.13] gh-146615: Fix format specifiers in Objects/ directory (GH-146620) (#147705)
* Fix format specifiers in vgetargskeywordsfast_impl for improved error messages.
* Fix f-string syntax error message in tok_get_normal_mode.
2026-04-01 21:52:14 +00:00
Serhiy Storchaka e726d28a23 [3.13] gh-146615: Fix format specifiers in Python/ directory (GH-146619) (GH-146654)
(cherry picked from commit dcb260eff2)

Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
2026-03-31 09:16:44 +00:00
Miss Islington (bot) fc4b4221e5 [3.13] gh-146244: Fix initconfig.c SET_ITEM macro leaks dict on expression failure (GH-146246) (GH-146433)
(cherry picked from commit 9343518c6f)

Co-authored-by: Wulian233 <1055917385@qq.com>
2026-03-25 19:32:20 +00:00
T. Wouters 684e7af8cd [3.13] gh-142183: Cache one datachunk per tstate to prevent alloc/dealloc thrashing (GH-145789) (#146123)
* gh-142183: Cache one datachunk per tstate to prevent alloc/dealloc thrashing (GH-145789) (#145828)

Cache one datachunk per tstate to prevent alloc/dealloc thrashing when repeatedly hitting the same call depth at exactly the wrong boundary.

Move new _ts member to the end to not mess up remote debuggers' ideas of the
struct's layout. (The struct is only created by the runtime, and the new
field only used by the runtime, so it should be safe.)

(cherry picked from commit 706fd4ec08)
(cherry picked from commit 19cbcc0f85)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
2026-03-24 02:27:57 +01:00
Sergey Miryanov eda53e6cf1 [3.13] GH-91636: Clear weakrefs created by finalizers. (GH-136401) (GH-144214)
Weakrefs to unreachable garbage that are created during running of
finalizers need to be cleared.  This avoids exposing objects that
have `tp_clear` called on them to Python-level code.
(cherry picked from commit b6b99bf7f1)

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
2026-03-24 00:50:41 +01:00
Miss Islington (bot) 53b544a6a7 [3.13] gh-146092: Handle _PyFrame_GetFrameObject() failures properly (GH-146124) (GH-146132) (#146138)
[3.14] gh-146092: Handle _PyFrame_GetFrameObject() failures properly (GH-146124) (GH-146132)

gh-146092: Handle _PyFrame_GetFrameObject() failures properly (GH-146124)

* Fix _PyFrame_GetLocals() and _PyFrame_GetLocals() error handling.
* _PyEval_ExceptionGroupMatch() now fails on _PyFrame_GetLocals()
  error.
(cherry picked from commit 8eeb800faf)


(cherry picked from commit e1e4852133)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-18 21:23:26 +01:00
Gregory P. Smith 102cd61763 [3.13] gh-145990: sort --help-env first section by name (others and xoptions already sorted) (GH-146003)
* sort `--help-env` sections by environment variable name
  Only needed in the first section, in 3.13 the second section was already sorted.
* regression test for --help-env & --help-xoptions sort order

Manual backport of GH-145997
2026-03-15 22:35:53 +00:00
Miss Islington (bot) 321daaba4e [3.13] gh-145701: Fix __classdict__ & __conditional_annotations__ in class-scope inlined comprehensions (GH-145702) (#145711)
* gh-145701: Fix `__classdict__` & `__conditional_annotations__` in class-scope inlined comprehensions (GH-145702)
(cherry picked from commit 63eaaf9599)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>

* Add `:oss-fuzz:` macro support

Backports part of https://github.com/python/cpython/commit/255e79fa955ac5ffef9eb27087e8b1373e98e3bd.

---------

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2026-03-09 14:44:31 -07:00
Ken Jin 85f8e76705 [3.13] gh-145008: Maintain stack consistency in CALL_BOUND_METHOD_EXACT_ARGS (GH-145015) 2026-03-03 04:09:02 +08:00
Miss Islington (bot) 22af3d5104 [3.13] gh-145092: Fix compiler warning for memchr() and wcschr() returning const pointer (GH-145093) (GH-145101)
(cherry picked from commit faea32b729)

Co-authored-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-02-22 08:28:24 +00:00
Peter Bierma 9314ec23a6 [3.13] gh-144601: Avoid sharing exception objects raised in a PyInit function across multiple interpreters (GH-144602) (GH-144880)
(cherry picked from commit fd6b639a49)
2026-02-16 16:05:55 +00:00
Pablo Galindo Salgado 0151abcd9f [3.13] gh-144766: Fix a crash in fork child process when perf support is enabled. (GH-144795) (#144818)
(cherry picked from commit 5922149a50)

Co-authored-by: Yilei <hi@mangoumbrella.com>
2026-02-14 17:52:42 +00:00
Gregory P. Smith c117ef1a1c [3.13] gh-143650: Fix importlib race condition on import failure (GH-143651) (#144697)
gh-143650: Fix importlib race condition on import failure (GH-143651)

Fix a race condition where a thread could receive a partially-initialized
module when another thread's import fails. The race occurs when:

1. Thread 1 starts importing, adds module to sys.modules
2. Thread 2 sees the module in sys.modules via the fast path
3. Thread 1's import fails, removes module from sys.modules
4. Thread 2 returns a stale module reference not in sys.modules

The fix adds verification after the "skip lock" optimization in both Python
and C code paths to check if the module is still in sys.modules. If the
module was removed (due to import failure), we retry the import so the
caller receives the actual exception from the import failure rather than
a stale module reference.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

cherry picked from ac8b5b6890
2026-02-11 06:37:25 +00:00
Peter Bierma 78a37d521e [3.13] gh-144307: Fix a reference leak during module teardown (GH-144308) (GH-144328)
(cherry picked from commit 219b7ac9d5)

Signed-off-by: Yongtao Huang <yongtaoh2022@gamil.com>
Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2026-01-29 19:18:39 +00:00
Victor Stinner e752ea9eb9 [3.13] gh-144194: Fix mmap failure check in perf_jit_trampoline.c (#143713) (#144304)
gh-144194: Fix mmap failure check in perf_jit_trampoline.c (#143713)

mmap() returns MAP_FAILED ((void*)-1) on error, not NULL. The current
check never detects mmap failures, so jitdump initialization proceeds
even when the memory mapping fails.

(cherry picked from commit 8fe8a94a7c)

Co-authored-by: stratakis <cstratak@redhat.com>
2026-01-28 14:15:39 +00:00
Jelle Zijlstra bc92e7878f [3.13] gh-144169: Fix three crashes in AST objects with non-str kwargs (GH-144178) (#144260)
(cherry picked from commit 639c1ad4f1)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-01-27 20:37:35 -08:00
Miss Islington (bot) e4e36a716a [3.13] gh-142779: Initialize reserved field for proper padding (GH-142780) (#144160)
gh-142779: Initialize reserved field for proper padding (GH-142780)

The jitdump specification specifies a reserved field for padding.

Initialize it so no garbage data is embedded in the jitdump files.
(cherry picked from commit 77bf4ba732)

Co-authored-by: stratakis <cstratak@redhat.com>
2026-01-22 17:29:57 +00:00
Serhiy Storchaka 149ecbb9a9 [3.13] gh-142829: Fix use-after-free in Context.__eq__ via re-entrant ContextVar.set (GH-142905) (GH-143871)
(cherry picked from commit a4086d7f89)

Co-authored-by: A.Ibrahim <abdulrasheedibrahim47@gmail.com>
2026-01-15 15:00:44 +00:00
Miss Islington (bot) 8c6d87693b [3.13] gh-106287: Do not write objects after an unmarshalling error (GH-132715) (GH-143833)
Writing out an object may involve a slot lookup, which is not safe to do with
an exception raised. In debug mode an assertion failure will occur if this
happens.
(cherry picked from commit ce8f5f98c6)

Co-authored-by: Duane Griffin <duaneg@dghda.com>
2026-01-14 11:48:52 +00:00
Shamil ab8224697a [3.13] gh-140306: Clear uncaught exception info after applying error in subinterpreter (GH-140397) 2026-01-12 18:19:57 +02:00
Bénédikt Tran 733a5cf51c [3.13] gh-143377: fix crashes in _interpreters.capture_exception (GH-143418) (#143653)
(cherry picked from commit ce6bae92da)
2026-01-10 13:59:14 +00:00
Miss Islington (bot) 57c56b0fb1 [3.13] gh-143547: Fix PyErr_FormatUnraisable() fallback (GH-143557) (GH-143603) (#143612)
[3.14] gh-143547: Fix PyErr_FormatUnraisable() fallback (GH-143557) (GH-143603)

gh-143547: Fix PyErr_FormatUnraisable() fallback (GH-143557)

Hold a strong reference to 'hook' while calling the default
unraisable took to log hook failure.
(cherry picked from commit 1d0baf1ae4)


(cherry picked from commit 39a2bcf949)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-01-09 15:33:25 +00:00
Pablo Galindo Salgado de34f6d404 [3.13] gh-143228: Fix UAF in perf trampoline during finalization (GH-143233) (#143248) 2025-12-28 14:32:16 +00:00
Stan Ulbrych e132893cc7 [3.13] gh-143135: Fix sys.flags.inspect when PYTHONINSPECT=0 (GH-143136) (GH-143168)
(cherry picked from commit 3509fa5a12)
2025-12-25 12:57:20 +02:00
Mikhail Efimov 4504ff89d5 [3.13] gh-140373: Correctly emit PY_UNWIND event when generator is closed (GH-140767) (#140821) 2025-12-20 16:21:11 +02:00
stratakis 4b8c9f5a7b [3.13] gh-142776: Ensure fp file descriptor is closed on all code paths in import.c (GH-142777) (#142989)
gh-142776: Ensure fp file descriptor is closed on all code paths in import.c (GH-142777)

(cherry picked from commit 6a4f10325d)
2025-12-20 12:48:42 +05:30
Savannah Ostrowski 8f7c4f1cef [3.13] GH-100964: Fix reference cycle in exhausted generator frames (G… (#142904)
* [3.13] GH-100964: Fix reference cycle in exhausted generator frames (GH-141112)
(cherry picked from commit 92243dc62c)

Co-authored-by: Savannah Ostrowski <savannah@python.org>
2025-12-17 20:04:53 +00:00
Miss Islington (bot) 5e1a9c8392 [3.13] gh-142873: Do not check for PyContextVar_CheckExact twice in PyContextVar_Set (GH-142874) (#142894)
gh-142873: Do not check for `PyContextVar_CheckExact` twice in `PyContextVar_Set` (GH-142874)
(cherry picked from commit e61a447d0e)

Co-authored-by: sobolevn <mail@sobolevn.me>
2025-12-17 17:04:39 +00:00
Bartosz Sławecki 3e45440382 [3.13] gh-142737: Handle lost io.open in _Py_FindSourceFile (GH-142747) (GH-142774)
(cherry picked from commit f277781bba)
2025-12-15 23:27:15 +00:00
Stan Ulbrych 9b24418867 [3.13] gh-142571: Check for errors before calling each syscall in PyUnstable_CopyPerfMapFile() (GH-142460) (#142602)
Co-authored-by: AZero13 <gfunni234@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2025-12-11 22:08:08 +00:00
Kumar Aditya fda856f368 [3.13] gh-142048: Fix lost gc allocations count on thread cleanup (GH… (#142506)
[3.13] gh-142048: Fix lost gc allocations count on thread cleanup (GH-142233)
(cherry picked from commit 49b1fb43f6)

Co-authored-by: Kevin Wang <kevmo314@gmail.com>
2025-12-11 15:07:38 +05:30
Serhiy Storchaka 93d5c481af [3.13] gh-141370: Fix undefined behavior when using Py_ABS() (GH-141548) (#142304)
(cherry picked from commit 706fdda8b3)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-12-05 15:52:12 +00:00
Sam Gross 01393ffbe6 [3.13] gh-142048: Fix quadratically increasing GC delays (gh-142051) (#142167)
The GC for the free threaded build would get slower with each collection due
to effectively double counting objects freed by the GC.
(cherry picked from commit eb892868b3)

Co-authored-by: Kevin Wang <kevmo314@gmail.com>
2025-12-02 00:31:36 +00:00
Itamar Oren 385688d4b4 [3.13] gh-140011: Delete importdl assertion that prevents importing embedded modules from packages (GH-141605) (#141987)
gh-140011: Delete importdl assertion that prevents importing embedded modules from packages (GH-141605)

(cherry picked from commit 27f62eb711)
2025-11-28 23:31:11 -08:00
Victor Stinner 80b752285d [3.13] gh-116008: Detect freed thread state in faulthandler (#141988) (#142017)
gh-116008: Detect freed thread state in faulthandler (#141988)

Add _PyMem_IsULongFreed() function.

(cherry picked from commit d5d9e89dde)
2025-11-27 17:55:31 +01:00
Sam Gross dbb539efc3 [3.13] gh-120158: Fix inconsistent monitoring state when setting events too frequently (gh-141845) (gh-141880)
If we overflowed the global version counter (i.e., after 2*24 calls to
`_PyMonitoring_SetEvents`), we bailed out after setting global monitoring
events but before instrumenting code objects, which led to assertion errors
later on.

Also add a `time.sleep()` to `test_free_threading.test_monitoring` to avoid
overflowing the global version counter.
(cherry picked from commit e457d60daa)
2025-11-23 15:30:37 +00:00
Pablo Galindo Salgado 7e1a0dbc07 [3.13] gh-141579: Fix perf_jit backend in sys.activate_stack_trampoline() (GH-141580) (#141582) 2025-11-15 03:17:49 +00:00
Bénédikt Tran 718886f6c6 [3.13] gh-140530: fix a reference leak in an error path for raise exc from cause (GH-140908) (#141283)
gh-140530: fix a reference leak in an error path for `raise exc from cause` (#140908)

Fix a reference leak in `raise E from T` when `T` is an exception
subtype for which `T.__new__` does not return an exception instance.

(cherry picked from commit 0c77e7c23b)
2025-11-09 15:57:26 +01:00
Victor Stinner 43882c7c4e [3.13] gh-140815: Fix faulthandler for invalid/freed frame (#140921) (#140985)
gh-140815: Fix faulthandler for invalid/freed frame (#140921)

faulthandler now detects if a frame or a code object is invalid or
freed.

Add helper functions:

* _PyCode_SafeAddr2Line()
* _PyFrame_SafeGetCode()
* _PyFrame_SafeGetLasti()

_PyMem_IsPtrFreed() now detects pointers in [-0xff, 0xff] range
as freed.

(cherry picked from commit a84181c31b)
2025-11-05 18:39:28 +01:00
Shamil fd6df66624 [3.13] gh-140301: Fix memory leak in subinterpreter PyConfig cleanup (GH-140303) (#140684)
[3.13] gh-140301: Fix memory leak in subinterpreter `PyConfig` cleanup (GH-140303)
(cherry picked from commit a615fb49c9)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-10-27 19:42:13 +00:00
Stan Ulbrych 1cc2c954d6 [3.13] gh-140471: Fix buffer overflow in AST node initialization with malformed _fields (GH-140506) (#140510)
(cherry picked from commit 95953b692d)
2025-10-24 00:38:02 +01:00
Serhiy Storchaka d7473f7a47 [3.13] gh-140306: Fix memory leaks in cross-interpreter data handling (GH-140307) (GH-140357)
(cherry picked from commit f9323213c9)

Co-authored-by: Shamil <ashm.tech@proton.me>
2025-10-20 10:13:15 +00:00
Serhiy Storchaka 92f7965cf6 [3.13] gh-139640: Fix swallowing syntax warnings in different modules (GH-139755) (GH-140119)
Revert GH-131993.

Fix swallowing some syntax warnings in different modules if they accidentally
have the same message and are emitted from the same line.

Fix duplicated warnings in the "finally" block.

(cherry picked from commit 279db6bede)
2025-10-14 15:46:11 +00:00
Sam Gross 16d2e97cf3 [3.13] gh-137400: Fix thread-safety issues when profiling all threads (gh-137518) (gh-137733)
There were a few thread-safety issues when profiling or tracing all
threads via PyEval_SetProfileAllThreads or PyEval_SetTraceAllThreads:

* The loop over thread states could crash if a thread exits concurrently
  (in both the free threading and default build)
* The modification of `c_profilefunc` and `c_tracefunc` wasn't
  thread-safe on the free threading build.
(cherry picked from commit a10152f8fd)
2025-10-09 11:42:47 -04:00
Kumar Aditya dac827cb98 [3.13] gh-139748: fix leaks in AC error paths when using unicode FS-b… (#139792)
* [3.13] gh-139748: fix leaks in AC error paths when using unicode FS-based converters (GH-139765)
(cherry picked from commit b04a57deef)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-10-08 22:21:49 +05:30