Commit Graph
16440 Commits
Author SHA1 Message Date
Neil SchemenauerandGitHub 03875414cb gh-159136: Keep eval-frame recorded function names alive (gh-160836)
Hold a strong reference to func_name in both recording hooks before
PyList_Append can detach while acquiring the recording list lock.
2026-10-29 10:16:59 -07:00
131a3a66c5 gh-160898: Reject null bytes in socket.getaddrinfo() host and port (#160899)
Co-authored-by: Stan Ulbrych <[email protected]>
2026-10-29 17:15:29 +00:00
Dmitry SpikhalskyandGitHub 756319503f gh-158159: Fix use-after-free in asyncio Task.get_name() (#158180) 2026-10-29 22:30:36 +05:30
Cody MaloneyandGitHub 7b727ab601 gh-160781: Fix BytesIO overflow handling for large sizes (#160783) 2026-10-29 13:54:46 +00:00
Cody MaloneyandGitHub 0bfee22390 gh-160781: Fix StringIO.truncate() rejecting sizes above 2**31 - 1 on Windows (#160784) 2026-10-29 13:52:42 +00:00
Michael J. SullivanandGitHub 312c427fe4 gh-158192: expose the future in asyncio FutureIter as fi_future (#158470) 2026-10-28 13:47:42 +05:30
Kumar AdityaandGitHub c79146a9eb gh-160804: Support generator based awaitables in asyncio introspection (#160805) 2026-10-28 08:14:16 +00:00
Itamar OrenandGitHub 0e35313484 gh-160689 : Link only the bootstrap modules into the build helper programs (#160537)
The build-helper programs (`Programs/_freeze_module` and `_bootstrap_python`) don't need to link extension modules that they don't need.

This PR makes sure the helper programs get only the modules they need to do their job, regardless of what the build configuration sets for the final built runtime and interpreter.

This follows the same pattern as what `PCbuild/_freeze_module.vcxproj` does with `PC/config_minimal.c`, and lets "extra" builtin modules (from `Setup.local` or `MODULE_BUILDTYPE=static`) depend on frozen modules or `getpath`.
2026-10-26 15:09:33 -07:00
Stan UlbrychandGitHub c5d09789ea Fix ignored error returns in sys initialization, _ctypes and _interpchannels (#160614) 2026-10-26 14:37:44 +00:00
1c327a4464 gh-144650: Support vectorcall for _decimal.Decimal (#158207)
Co-authored-by: Cody Maloney <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
2026-10-26 00:29:42 +00:00
d441a118fa gh-151126: Set MemoryError on allocation failure in CJK codec macros (#156292)
Co-authored-by: Stan Ulbrych <[email protected]>
2026-10-25 17:36:04 +00:00
Gregory P. SmithandGitHub 23a5ba1c93 gh-160549: Fix crash when freeing a busy multi-threaded ZstdCompressor (GH-160550)
ZSTD_freeCCtx() frees a dictionary loaded with ZSTD_CCtx_loadDictionary()
before it stops the worker threads.  Make libzstd wait for unfinished
jobs before freeing the compression context of a ZstdCompressor that
uses worker threads and a ZstdDict.

Works around https://github.com/facebook/zstd/issues/4862
2026-10-24 22:38:04 -07:00
Gregory P. SmithandGitHub b949033ae8 gh-160535: Keep the ZstdDict alive until the zstd context is freed (GH-160536)
The garbage collector could release a ZstdCompressor's dictionary, or
the digested dictionaries cached by the ZstdDict, while worker threads
of the compression context were still reading them.  They are now only
released on deallocation, after the context has been freed.

ANT-2026-CT3P1CSJ

+ Visit the type in the compressor and decompressor traverse; move NEWS to Library
2026-10-24 22:31:45 -07:00
b26fc41b5c Remove obsolete and unused configure macros (#159513)
Co-authored-by: Emma Smith <[email protected]>
2026-10-25 05:18:16 +00:00
Jelle ZijlstraandGitHub 656af533dc gh-159739: Keep sqlite3 cursor metadata and factories valid during queries (#160403)
A cursor exposed its description tuple before filling in all the columns, so an allocation failure or a reader on a free-threaded build could encounter an unset tuple entry. An allocation failure could also clear lastrowid and crash the next execute. Build new metadata before replacing the old values and synchronize reads and writes. Keep a strong reference to each row or text factory while it is called so replacing the factory during a fetch cannot destroy an active callable.
2026-10-24 13:46:15 -07:00
Jelle ZijlstraandGitHub 665bda98e8 gh-159739: Keep text I/O state valid across reentrant callbacks (#160398)
A raw read can reinitialize a TextIOWrapper as write-only, and codec callbacks or finalizers can release an encoder, decoder, or decoded chunk while a read or write still needs it. This can crash the interpreter. Check that a decoder is still available after reading, keep codecs alive across calls, and read the chunk length before transferring ownership. Also recheck StringIO after converting the truncate size because __index__() can close the stream.
2026-10-24 13:45:41 -07:00
Inada NaokiandGitHub 94d16d2e13 gh-89977: Keep the GIL for short socket calls (#157981) 2026-10-24 20:51:24 +09:00
7dd8b4736a gh-160040: Distrust compromised eMudhra intermediate CA keys (CVE-2026-115557) (GH-160042)
The ssl module now rejects TLS certificate chains that contain any of a set of
compromised eMudhra intermediate CA keys.  This is an extraordinary measure and
a last line of defense: removing trust is primarily the job of the platform root
store, and the built-in denylist only blocks connections while that update has
not yet reached the OS, a container image, or a bundled trust store in various
Python packages.  Entries are added to the denylist only under a very high
threshold.

The denylist matches on the public key (the SHA-256 digest of the RFC-5280
SubjectPublicKeyInfo), so it also covers the cross-signed certificates that
reuse one of the distrusted keys.

---------

Signed-off-by: Christian Heimes <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
2026-10-24 05:40:49 +00:00
Jelle ZijlstraandGitHub c2b7e0a866 gh-159739: Guard cProfile against reentry while processing an external timer (#160405)
An external timer can run Python again when the profiler converts or releases its result or reports an unraisable exception. Calling clear() or disable() at that point could free a profiling context still in use. Calling Profiler.__init__() from the timer could also destroy the active callable. Keep the guard active through result handling and reject reinitialization while an external timer is running.
2026-10-23 21:59:01 -07:00
46edd6fa41 gh-89730: Implement support for Encrypted Client Hello (ECH) in ssl (GH-160318)
Co-authored-by: irl <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
2026-10-23 20:02:23 -04:00
Jelle ZijlstraandGitHub a96fbdca7f gh-159739: Preserve CJK codec state across chunk boundaries and callbacks (#160400)
The HZ encoder can consume a tilde after writing only its first escape byte. A split ISO-2022 escape can exceed the incremental decoder’s pending buffer, and a reset can leave the previous character set selected. Reserve space for both HZ bytes before consuming the tilde, allow the full pending escape, and restore the initial ISO-2022 state on reset. Keep the native codec table and the active encoder error policy alive so replacing their Python owners cannot leave a codec using freed memory.
2026-10-23 13:45:46 -07:00
Pengyu LeeandGitHub e03def8c23 Fix inaccurate wording in multiple decimal module docstrings (#155688) 2026-10-23 12:54:38 -07:00
Jelle ZijlstraandGitHub 0ba58e7e83 gh-159739: Handle pyexpat configuration changes during callbacks (#160399)
A character data callback can disable buffering or remove the next event handler during a flush. Interning an attribute name can also change ordered_attributes while pyexpat is filling the attribute container. Using the freed buffer, cleared handler, or wrong container type can crash the interpreter. Clear the buffered length before dispatch, keep the active handler alive, recheck the buffer and handlers after callbacks, and use one attribute mode for the whole start event.
2026-10-23 12:42:06 -07:00
Stan UlbrychandGitHub b341b81e92 gh-115810: Expose the name attribute of datetime.timezone (#131210) 2026-10-23 20:21:28 +01:00
Zanie BlueandGitHub 74c91a6fbf gh-160359: Accept older musl getdents64 buffer declarations (#160365)
Older musl headers expose `getdents64` as an alias for `getdents`, whose buffer parameter is `struct dirent *`. Passing the raw character buffer triggers an incompatible-pointer diagnostic. Pass it through `void *` to support both that interface and the glibc declaration.

Ports PBS's [`patch-posixsubprocess-musl-getdents64.patch`](https://github.com/astral-sh/python-build-standalone/blob/0c5e581b54a4736cdbbe68bdd6d7e571a1dca11e/cpython-unix/patch-posixsubprocess-musl-getdents64.patch).
2026-10-23 17:14:45 +00:00
Petr ViktorinandGitHub 8335bcbf26 gh-160208: Add a private wrapper around __STDC_VERSION__ (GH-160376)
The wrapper is undefined on C++, where it can have an arbitrary
compiler-specific value.
2026-10-23 17:40:21 +02:00
6854e79163 gh-158252: Add a C implementation for strptime (#158253)
Co-authored-by: Stan Ulbrych <[email protected]>
2026-10-23 15:23:02 +00:00
a4ac2445c5 gh-160171: Fix ssl get_unverified_chain() on resumed server sessions (GH-160172)
Include the client's certificate when the session was resumed from a
ticket, and return [] instead of raising AttributeError when the client
sent no certificate.

ANT-2026-2RMA0IPV

Co-authored-by: Bénédikt Tran <[email protected]>
2026-10-23 06:26:33 +00:00
3fc4d1f9b3 gh-87613: Allow Argument Clinic vectorcall on heap types (#160115)
Heap types have no static type object so switch from `Py_Is` to an
assert that the shadowed `tp_new` / `tp_init` function is the expected
one to validate the vectorcall is only used with the right type.

Heap types can have zero-argument `__new__` and `__init__` so add
support  for that producing the same error message via a new helper
`_PyArg_NoPositionalStack()`.

Co-authored-by: Claude Opus 5.5 <[email protected]>
2026-10-23 03:13:30 +00:00
Donghee NaandGitHub 1a80f6d454 gh-114258: Update _ctypes and tokenize to use AC where it can be. (gh-160404) 2026-10-23 02:42:16 +00:00
Bénédikt TranandGitHub dfd2c7cce8 gh-146169: correctly handle re-entrant parsing calls in Expat handlers (#146566) 2026-10-23 02:03:12 +00:00
Gregory P. SmithandGitHub fd657b0674 gh-160181: Don't modify a hashed bytes buffer in place in io.BytesIO (GH-160182)
Treat the internal buffer as shared once its hash is cached, so the next
modification copies it, as gh-158219 did for bytearray.

ANT-2026-IZN6JY41
2026-10-23 00:36:04 +00:00
Sumit Kumar DasandGitHub 85599d33d7 gh-156399: Don't specialize LOAD_ATTR_MODULE for module subclasses (GH-156474)
Fixes https://github.com/python/cpython/issues/156399
2026-10-22 16:53:35 -07:00
Jelle ZijlstraandGitHub 8bfda5553c gh-159739: Recheck BytesIO state after converting truncate size (#160190)
A size object's __index__() can close a BytesIO or export its buffer after truncate() checks the stream. Continuing can dereference a cleared buffer or resize storage behind a live view. Recheck the stream state after size conversion. Backport to 3.15 and 3.14; on 3.14, put the regression test in Lib/test/test_memoryio.py.
2026-10-22 15:26:56 -07:00
Jelle ZijlstraandGitHub 4df47d8e60 gh-159739: Keep SQLite list parameters alive while binding (#160192)
When a SQL parameter sequence is an exact list, sqlite3 retrieved an element as a borrowed reference before taking ownership. On free-threaded builds another thread can replace it in between, so binding can use a freed object and crash. Fetch a strong reference atomically. Backport to 3.15 and 3.14.
2026-10-22 21:50:43 +00:00
Itamar OrenandGitHub 5b55b50222 gh-106045: Keep searching from venv home when the resolved base executable has no stdlib (#160123)
GH-156483 made `getpath` locate a venv's base installation relative to the *resolved* base executable instead of the `home` key in `pyvenv.cfg`. When the resolved executable lives outside the installation tree (e.g. a launcher binary symlinked into it), nothing is found there and discovery falls back to the compiled-in `PREFIX`. The venv then either fails to start or silently runs with another installation's standard library.

This PR:

- Keeps GH-156483's behavior when the resolved executable's directory locates a standard library (`pybuilddir.txt`, the stdlib zip, or `os.py`). Otherwise it keeps searching from `home`, as before GH-156483.
- In that fallback case, still searches the resolved executable's directory for `lib-dynload` when determining `exec_prefix`: after `prefix`, before `home` and the compiled-in `EXEC_PREFIX`. Layouts with a separate exec prefix (e.g. `./configure --exec-prefix`) then keep loading extension modules from the right place, and a stale `lib-dynload` near the `home` symlink can't take precedence over the one beside the resolved executable.

The tests added by GH-156483 pass unchanged. Three new `test_getpath` cases cover the launcher-outside-the-installation and separate-exec-prefix layouts, and a misleading `lib-dynload` near `home`; each fails without this change.

<details>
<summary>Reproducer</summary>

On `main` (0a86a34), with a plain `./configure --prefix=$HOME/py-under-test && make && make install`:

```sh
#!/bin/sh
# Usage: venv-home-repro.sh <installed-prefix> <X.Y>
set -eu
PREFIX=$1; VER=$2
W=$(mktemp -d)
mkdir -p "$W/runtime/bin" "$W/runtime/lib" "$W/launcher"
cp -R "$PREFIX/lib/python$VER" "$W/runtime/lib/"
cp "$PREFIX/bin/python$VER" "$W/launcher/python3"
ln -s "$W/launcher/python3" "$W/runtime/bin/python3"
PYTHONHOME="$W/runtime" "$W/runtime/bin/python3" -m venv --without-pip "$W/venv"
grep '^home' "$W/venv/pyvenv.cfg"
echo "expected base_prefix: $W/runtime"
"$W/venv/bin/python" -c 'import os, sys; print("actual base_prefix:", sys.base_prefix); print("os.py loaded from:", os.__file__)'
```

Before:

```
home = /tmp/tmp.NFug9wEr4h/runtime/bin
expected base_prefix: /tmp/tmp.NFug9wEr4h/runtime
actual base_prefix: /home/user/py-under-test
os.py loaded from: /home/user/py-under-test/lib/python3.16/os.py
```

(With `$HOME/py-under-test/lib/python3.16` removed, the venv instead fails with `ModuleNotFoundError: No module named 'encodings'`.)

After:

```
home = /tmp/tmp.8Zne2otFrw/runtime/bin
expected base_prefix: /tmp/tmp.8Zne2otFrw/runtime
actual base_prefix: /tmp/tmp.8Zne2otFrw/runtime
os.py loaded from: /tmp/tmp.8Zne2otFrw/runtime/lib/python3.16/os.py
```

</details>
2026-10-22 21:35:18 +00:00
Jelle ZijlstraandGitHub c6796a1268 gh-159739: Validate newline replacement in TextIOWrapper.write (#160191)
A str subclass can override replace() and return a non-string while TextIOWrapper.write() translates newlines. The C implementation then treats the result as Unicode and can crash. Reject an invalid replacement with TypeError. Backport to 3.15 and 3.14; on 3.14, put the regression test in Lib/test/test_io.py.
2026-10-22 14:17:22 -07:00
Jelle ZijlstraandGitHub 3e19e0408d gh-159739: Detect recursive untyped ctypes arguments (#160194)
_as_parameter_ chains were recursion-checked for typed arguments but not for foreign calls without argtypes. A cyclic chain could exhaust the C stack and crash before the function was called. Apply the same recursion guard to untyped conversion. Backport to 3.15 and 3.14.
2026-10-22 14:16:04 -07:00
d6b77c8686 gh-156780: Emscripten: support building CPython with static linking (#156781)
Adds the ability to build Emscripten statically, so that it can be linked in as
an embedded library. Includes a test of the embedding case.
---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Co-authored-by: Russell Keith-Magee <[email protected]>
2026-10-22 19:58:32 +00:00
Jelle ZijlstraandGitHub dcbc45356e gh-159739: Keep the instance type alive during ABC subclass checks (#160198)
When an instance advertises a __class__ different from its actual type, ABCMeta.__instancecheck__ performs two subclass checks. The first callback can change the instance's actual type and allow its old type to be collected before the second check, causing a crash. Keep the original type alive through both checks. Backport to 3.15 and 3.14.
2026-10-22 12:37:22 -07:00
Jelle ZijlstraandGitHub cc36604f7b gh-159739: Fully clear the unpickler memo (#160173)
Clearing an Unpickler memo left its sequential index and sparse entries intact, so reusing the unpickler for an independent record could raise UnpicklingError or retrieve an object from a previous record. Replace the memo and reset all of its state before releasing the old entries. Backport to 3.15; manually backport only the counter reset to 3.14, which has no sparse memo.
2026-10-22 19:29:51 +00:00
Jelle ZijlstraandGitHub 7c873199d4 gh-159739: Preserve ctypes base metadata when cloning fails (#160174)
When creating a ctypes structure subclass, cloning its layout initially copied pointers to buffers owned by the base class. If a later allocation failed, cleaning up the subclass could free those buffers, leaving the base with invalid metadata and potentially causing a crash. Detach the owned pointers until their copies have been allocated. Backport to 3.15 and 3.14.
2026-10-22 18:27:03 +00:00
Jelle ZijlstraandGitHub 4a61673276 gh-159739: Allocate thread-local state before constructing the object (#160166)
If allocating a thread-local object’s internal dictionary or watchdog set fails, a subclass finalizer can run with that state missing. Accessing a thread-local attribute then dereferences the missing state and crashes; allocate both containers before creating the object. Backport to 3.15 and 3.14.
2026-10-22 11:22:09 -07:00
Jelle ZijlstraandGitHub 5ce1ef3e87 gh-159739: Keep SimpleQueue valid after buffer allocation fails (#160165)
If allocating a SimpleQueue buffer fails, the partially constructed object reports nonzero capacity despite having no storage. A subclass finalizer that calls put() then writes through a NULL pointer and crashes; publish the capacity only after allocation succeeds. Backport to 3.15 and 3.14.
2026-10-22 11:21:53 -07:00
Russell Keith-MageeandGitHub eb229a9b40 gh-49960: Allow ctypes callbacks to return struct/union types (GH-157974) 2026-10-22 17:52:55 +00:00
sobolevnGitHubMuse Code (Meta Muse Spark)Lukasz Langa
ab2c947f43 gh-94808: add tests covering PySequence_[InPlace_]Repeat (#99196)
Drop the basic repeat/in-place-repeat tests: test_abstract.py now
covers those paths via _testlimitedcapi (including corner counts,
MemoryError, TypeError and NULL cases). Keep the subtype and error
tests unique to this PR.

Add test_sequence_repeat_numeric_fallback for the previously
untested nb_multiply fallback in PySequence_Repeat.

Assert exact result types with assertIs: comparing against
CustomList(...) only checks contents, and repeat of a builtin
subtype returns the exact builtin type.

Co-authored-by: Muse Code (Meta Muse Spark)
Co-authored-by: Lukasz Langa <[email protected]>
2026-10-22 10:06:49 -07:00
Stan UlbrychandGitHub a930e524cb Fix unchecked NULL returns in several C modules (#160213) 2026-10-22 15:55:09 +00:00
Lazizbek ErgashevandGitHub e60a9da991 gh-158126: Avoid creating AttributeError for optional Pickler attribute lookups (GH-158148) 2026-10-22 14:44:40 +00:00
Jelle ZijlstraandGitHub 87eaef1171 gh-159739: Respect readline limits after a short read (#159974)
Backport to 3.15 and 3.14. Both branches use a bytearray instead of PyBytesWriter; the test lives in Lib/test/test_io.py on 3.14.
2026-10-22 07:38:52 -07:00
Donghee NaandGitHub c58b7136b2 gh-114258: Use Argument Clinic for `__bool__` (GH-160057) 2026-10-22 05:45:16 +00:00