Commit graph

15763 commits

Author SHA1 Message Date
Michael Bommarito
446edda209
gh-148651: Fix refcount leak in _zstd decompressor options (#148657)
The option parsing in Modules/_zstd/decompressor.c had a missing Py_DECREF(value) before the early return -1 when PyLong_AsInt(key) fails. The identical code in Modules/_zstd/compressor.c line 158 has the fix.
2026-04-17 08:42:41 -07:00
Gleb Popov
afde75664e
gh-148484: Fix memory leak of iterator in array.array constructor (GH-148523) 2026-04-17 14:13:44 +02:00
Sergey B Kirpichev
769cc8338f
gh-148464: Add missing `__ctype_le/be__` attributes for complex types in the ctype module (GH-148485)
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
2026-04-17 14:09:09 +02:00
Dino Viehland
c0af5c024b
gh-146031: Allow keeping specialization enabled when specifying eval frame function (#146032)
Allow keeping specialization enabled when specifying eval frame function
2026-04-16 09:44:26 -07:00
Mark Shannon
600f4dbd54
GH-145668: Add FOR_ITER specialization for virtual iterators. Specialize GET_ITER. (GH-147967)
* Add FOR_ITER_VIRTUAL to specialize FOR_ITER for virtual iterators
* Add GET_ITER_SELF to specialize GET_ITER for iterators (including generators)
* Add GET_ITER_VIRTUAL to specialize GET_ITER for iterables as virtual iterators
* Add new (internal) _tp_iteritem function slot to PyTypeObject
* Put limited RESUME at start of genexpr for free-threading. Fix up exception handling in genexpr
2026-04-16 15:22:22 +01:00
Pieter Eendebak
1f6a09fb36
gh-100239: Specialize more binary operations using BINARY_OP_EXTEND (GH-128956) 2026-04-16 09:22:41 +01:00
Victor Stinner
70eb56be42
gh-148600: Add Modules/_ssl_data_40.h data (#148601)
The Modules/_ssl_data_40.h file was created with the commands:

python Tools/ssl/multissltests.py --steps=library --base-directory "$PWD/multissl" --openssl '4.0.0' --system Linux
python Tools/ssl/make_ssl_data.py multissl/src/openssl-4.0.0 Modules/_ssl_data_40.h

Update Modules/_ssl.c to include it on OpenSSL 4.0.0 and newer.

Update test_ssl for the new error message.
2026-04-15 15:59:02 +02:00
Pieter Eendebak
95cbd4a232
gh-146393: Optimize float division operations by mutating uniquely-referenced operands in place (JIT only) (GH-146397)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 02:08:04 +08:00
Bénédikt Tran
356a031de5
gh-146563: add exception note for invalid Expat handler return values (#146565) 2026-04-14 19:12:47 +02:00
Kumar Aditya
1aa7e7ee6d
gh-gh-131798: optimize LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN in the JIT (#148555) 2026-04-14 21:00:32 +05:30
Neko Asakura
52a7f1b7f8
gh-148510: restore func_version check in _LOAD_ATTR_PROPERTY_FRAME (GH-148528) 2026-04-14 22:44:39 +08:00
Hai Zhu
5ce0fe8b6c
gh-148378: Allow multiple consecutive recording ops per macro op (GH-148496) 2026-04-14 19:26:53 +08:00
Pablo Galindo Salgado
eb4c78df07
gh-148252: Fix stack depth calculation in binary reader on 32-bit platforms (#148253)
Compute ``final_depth`` in ``decode_stack_pop_push()`` and
``decode_stack_suffix()`` using ``uint64_t`` before validating it.

On 32-bit builds, using ``size_t`` arithmetic for ``keep + push`` can wrap
for large input values, causing the later bounds check to validate the wrong
final depth. Using a widened type keeps the validation aligned with the
actual result.
2026-04-13 23:43:55 +01:00
Pablo Galindo Salgado
289fd2c97a
gh-148178: Validate remote debug offset tables on load (#148187)
Treat the debug offset tables read from a target process as untrusted input
and validate them before the unwinder uses any reported sizes or offsets.

Add a shared validator in debug_offsets_validation.h and run it once when
_Py_DebugOffsets is loaded and once when AsyncioDebug is loaded. The checks
cover section sizes used for fixed local buffers and every offset that is
later dereferenced against a local buffer or local object view. This keeps
the bounds checks out of the sampling hot path while rejecting malformed
tables up front.
2026-04-13 22:22:23 +00:00
Charlie Lin
10d275fdf8
gh-148483: Use Py_GCC_ATTRIBUTE(unused) for stop_tracing label (GH-148481) 2026-04-13 21:05:34 +08:00
Stan Ulbrych
8fc66aef6d
gh-148395: Fix a possible UAF in {LZMA,BZ2,_Zlib}Decompressor (GH-148396)
Fix dangling input pointer after `MemoryError` in _lzma/_bz2/_ZlibDecompressor.decompress
2026-04-12 18:14:54 -07:00
Sacul
18d7d90ef9
gh-131798: Split _CHECK_AND_ALLOCATE_OBJECT into smaller uops (GH-148433)
Co-authored-by: Hai Zhu <haiizhu@outlook.com>
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
2026-04-13 02:31:24 +08:00
Shamil
235fa7244a
gh-142831: Fix use-after-free in json encoder during re-entrant mutation (gh-142851)
Hold strong references to borrowed items unconditionally (not only in                                                                        
free-threading builds) in _encoder_iterate_mapping_lock_held and                                                                             
_encoder_iterate_fast_seq_lock_held.  User callbacks invoked during                                                                          
encoding can mutate or clear the underlying container, invalidating                                                                          
borrowed references.                                                                                                                         
                                                                                                                                               
The dict iteration path was already fixed by gh-145244.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2026-04-12 00:14:50 +00:00
Gregory P. Smith
d761f539bd
gh-146287: Fix signed/unsigned mismatch in _hashlib_hmac_digest_size (GH-148407)
* gh-146287: use signed type for HMAC digest size to prevent unsigned wrapping

Change _hashlib_hmac_digest_size() return type from unsigned int to int
so that a hypothetical negative return from EVP_MD_size() is not
silently wrapped to a large positive value. Add an explicit check for
negative digest_size in the legacy OpenSSL path, and use SystemError
(not ValueError) since these conditions indicate internal invariant
violations. Also add debug-build asserts to EVP_get_block_size and
EVP_get_digest_size documenting that the hash context is always
initialized.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-04-12 00:02:56 +00:00
Ramin Farajpour Cami
8a466fa3d9
gh-145244: Fix use-after-free on borrowed dict key in json encoder (GH-145245)
In encoder_encode_key_value(), key is a borrowed reference from
PyDict_Next(). If the default callback mutates or clears the dict,
key becomes a dangling pointer. The error path then calls
_PyErr_FormatNote("%R", key) on freed memory.

Fix by holding strong references to key and value unconditionally
during encoding, not just in the free-threading build.

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2026-04-11 22:26:36 +00:00
Ramin Farajpour Cami
20994b1809
gh-145105: Fix crash in csv.reader with re-entrant iterator (GH-145106)
When a custom iterator calls next() on the same csv.reader from
within __next__, the inner iteration sets self->fields to NULL.
The outer iteration then crashes in parse_save_field() by passing
NULL to PyList_Append.

Add a guard after PyIter_Next() to detect that fields was set to
NULL by a re-entrant call, and raise csv.Error instead of crashing.
2026-04-11 15:18:02 -07:00
Ramin Farajpour Cami
c29d75610b
gh-145200: Fix EVP_MAC_CTX leak in hashlib HMAC on init failure (GH-145201)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-04-11 15:10:43 -07:00
Alper
afbe1373ac
gh-116738: Align bz2 unused_data getter to lzma implementation (GH-144351)
Align bz2 unused_data getter to lzma
2026-04-11 14:13:51 -07:00
Donghee Na
a71b043356
gh-148171: Convert CALL_BUILTIN_CLASS to leave arguments on the stack (gh-148381) 2026-04-11 23:01:25 +09:00
Stan Ulbrych
639f218f9c
Fix format string mismatch for uint64_t in _remote_debugging/threads.c (#148360) 2026-04-11 09:10:02 +01:00
Sacul
e872c19922
gh-148171: Convert variadic argument opcodes to leave their arguments on the stack (CALL_BUILTIN_FAST_WITH_KEYWORDS) (#148366) 2026-04-11 13:27:24 +08:00
Kumar Aditya
2b439da972
gh-148171: convert more variadic uops to leave input on stack in JIT (#148361) 2026-04-11 10:29:38 +05:30
Kumar Aditya
8f17140fc1
gh-131798: split _CALL_BUILTIN_CLASS to smaller uops (#148094) 2026-04-10 17:28:20 +00:00
Ken Jin
266247c9a6
gh-148171: Convert CALL_BUILTIN_FAST to leave inputs on the stack for refcount elimination in JIT (GH-148172) 2026-04-10 23:11:18 +08:00
Sacul
38d3aef375
gh-134584 : Optimize and eliminate redundant ref-counting for MAKE_FUNCTION in the JIT (GH-144963) 2026-04-09 22:22:53 +08:00
Max Bachmann
ee2775cfae
gh-148274: properly handle result from PyObject_VisitManagedDict (#148275) 2026-04-09 18:50:50 +05:30
Victor Stinner
b7e1d51e6b
gh-148241: Fix json serialization for str subclasses (#148249)
Fix json serialization: no longer call str(obj) on str subclasses.

Replace PyUnicodeWriter_WriteStr() with PyUnicodeWriter_WriteASCII()
and private _PyUnicodeWriter_WriteStr().
2026-04-09 13:50:44 +02:00
Kumar Aditya
458aca9237
gh-131798: fold super method lookups in JIT (#148231) 2026-04-09 13:25:01 +05:30
Stan Ulbrych
ee5232782f
Update and expand the 'Fuzz Tests for CPython' README (#148270) 2026-04-09 08:52:30 +01:00
Sacul
bb03c8bd02
gh-145866: Convert _CALL_METHOD_DESCRIPTOR_NOARGS to leave its inputs on the stack to be cleaned up by _POP_TOP (GH-148227) 2026-04-08 23:21:37 +08:00
Petr Viktorin
8923ca418c
gh-145921: Add "_DuringGC" functions for tp_traverse (GH-145925)
There are newly documented restrictions on tp_traverse:

    The traversal function must not have any side effects.
    It must not modify the reference counts of any Python
    objects nor create or destroy any Python objects.

* Add several functions that are guaranteed side-effect-free,
  with a _DuringGC suffix.
* Use these in ctypes
* Consolidate tp_traverse docs in gcsupport.rst, moving unique
  content from typeobj.rst there

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-04-08 09:15:11 +02:00
Ramin Farajpour Cami
957b2cca8e
gh-145846: Fix memory leak in _lsprof clearEntries() context chain (#145847)
clearEntries() only freed the top currentProfilerContext but did not
walk the previous linked list. When clear() is called during active
profiling with nested calls, all contexts except the top one were
leaked. Fix by iterating the entire linked list, matching the existing
freelistProfilerContext cleanup pattern.

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-04-07 22:56:19 +02:00
Stan Ulbrych
63d3c490d4
gh-101178: Fix UB in binascii.b2a_ascii85 (#148166) 2026-04-07 08:44:03 +01:00
Serhiy Storchaka
8bf8bf9292
gh-73613: Support Base32 and Base64 without padding (GH-147974)
Add the padded parameter in functions related to Base32 and Base64 codecs
in the binascii and base64 modules.  In the encoding functions it controls
whether the pad character can be added in the output, in the decoding
functions it controls whether padding is required in input.

Padding of input no longer required in base64.urlsafe_b64decode() by default.
2026-04-04 21:26:16 +03:00
Pablo Galindo Salgado
21fb9dc71d
gh-146527: Heap-allocate gc_stats to avoid bloating PyInterpreterState (#148057)
The gc_stats struct contains ring buffers of gc_generation_stats
entries (11 young + 3×2 old on default builds). Embedding it inline
in _gc_runtime_state, which is itself inline in PyInterpreterState,
pushed fields like _gil.locked and threads.head to offsets beyond
what out-of-process profilers and debuggers can reasonably read in
a single buffer (e.g. offset 9384 for _gil.locked vs an 8 KiB read
buffer).

Heap-allocate generation_stats via PyMem_RawCalloc in _PyGC_Init and
free it in _PyGC_Fini. This shrinks PyInterpreterState by ~1.6 KiB
and keeps the GIL, thread-list, and other frequently-inspected fields
at stable, low offsets.
2026-04-04 18:42:30 +01:00
Stan Ulbrych
fe9befc1ca
gh-145883: Fix two heap-buffer-overflows in _zoneinfo (#145885) 2026-04-04 13:29:17 +01:00
Kumar Aditya
e7bf8eac0f
gh-131798: split recursion check to _CHECK_RECURSION_LIMIT and combine checks (GH-148070) 2026-04-04 17:23:03 +08:00
Serhiy Storchaka
113038f940
gh-148016: Improve "Leading padding not allowed" error in Base32 and Base64 decoders (GH-148017)
It is now raised instead of "Excess padding not allowed" if all characters
preceding "=" were ignored.
2026-04-04 08:37:14 +00:00
Serhiy Storchaka
985216ced3
gh-148029: Fix error message for invalid number of Base32 characters (GH-148030)
Do not count ignored non-alphabet characters.
2026-04-04 11:07:19 +03:00
Kumar Aditya
7e275d4965
gh-131798: JIT inline function addresses of builtin methods (#146906) 2026-04-04 09:12:13 +05:30
Sergey Miryanov
c1b20a6d96
GH-145247: Use _PyTuple_FromPair in Modules (part 2) (#148003)
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-04-02 23:24:03 +02:00
Sergey Miryanov
0c100664bc
GH-145247: Use _PyTuple_FromPair in Modules (part 1) (#148000) 2026-04-02 23:20:13 +02:00
Ma Yukun
fc7a188fe7
gh-146613: Fix re-entrant use-after-free in itertools._grouper (#147962) 2026-04-02 19:04:58 +05:30
Victor Stinner
c1a4112c22
gh-147988: Initialize digits in long_alloc() in debug mode (#147989)
When Python is built in debug mode:

* long_alloc() now initializes digits with a pattern to detect usage of
  uninitialized digits.
* _PyLong_CompactValue() now makes sure that the digit is zero when the
  sign is zero.
* PyLongWriter_Finish() now raises SystemError if it detects uninitialized
  digits

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-04-02 11:55:34 +00:00
Petr Viktorin
a86963b3e2
gh-146636: Py_mod_abi mandatory for modules created from slots array (GH-146855) 2026-04-02 13:54:21 +02:00