Commit graph

15161 commits

Author SHA1 Message Date
Miss Islington (bot)
7cb15f93fe
[3.14] gh-141659: Fix bad file descriptor error in subprocess on AIX (GH-141660) (GH-141738)
/proc/self does not exist on AIX.
(cherry picked from commit 92c5de73b8)

Co-authored-by: Ayappan Perumal <ayappap2@in.ibm.com>
2025-11-19 08:05:01 +00:00
Gregory P. Smith
0d8fb0b852
[3.14] gh-137109: refactor warning about threads when forking (GH-141438) (GH-141614)
This splits the OS API specific functionality to get the number of threads out
from the fallback Python method and warning raising code itself.  This way the
OS APIs can be queried before we've run
`os.register_at_fork(after_in_parent=...)` registered functions which
themselves may (re)start threads that would otherwise be detected.

This is best effort.  If the OS APIs are either unavailable or fail, the
warning generating code still falls back to looking at the Python threading
state after the CPython interpreter world has been restarted and the
after_in_parent calls have been made.  The common case for most Linux and macOS
environments should work today.

This also lines up with the existing TODO refactoring, we may choose to expose
this API to get the number of OS threads in the `os` module in the future.

Note: This is a simplified backport that maintains the void return type
for warn_about_fork_with_threads() and keeps PyErr_Clear() in the warning path,
as the error handling changes from fd8f42d3d1 are not needed in 3.14.
2025-11-16 19:45:29 +00:00
Miss Islington (bot)
1cde019ecd
[3.14] gh-114203: skip locking if object is already locked by two-mutex critical section (GH-141476) (#141564)
gh-114203: skip locking if object is already locked by two-mutex critical section (GH-141476)
(cherry picked from commit f26ed455d5)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-11-14 18:38:30 +00:00
Miss Islington (bot)
79195df23c
[3.14] gh-140260: fix data race in _struct module initialization with subinterpreters (GH-140909) (#141501)
gh-140260: fix data race in `_struct` module initialization with subinterpreters (GH-140909)
(cherry picked from commit 63548b3699)

Co-authored-by: Shamil <ashm.tech@proton.me>
2025-11-13 17:23:22 +05:30
Miss Islington (bot)
0b44bc3379
[3.14] gh-124111: Fix TCL 9 thread detection (GH-141482)
(cherry picked from commit dc0987080e)

Co-authored-by: Michael Cho <michael@michaelcho.dev>
2025-11-12 22:43:31 +00:00
Miss Islington (bot)
ba73decce1
[3.14] gh-132657: add regression test for PySet_Contains with unhashable type (GH-141411) (#141468)
gh-132657: add regression test for `PySet_Contains` with unhashable type (GH-141411)
(cherry picked from commit 2ac738d325)

Co-authored-by: M Bussonnier <bussonniermatthias@gmail.com>
2025-11-12 15:49:09 +00:00
Mohsin Mehmood
92c14a91d2
[3.14] gh-141314: Fix TextIOWrapper.tell() assertion failure with standalone carriage return (GH-141331) (GH-141453)
The assertion was checking wrong variable (skip_back vs skip_bytes).
(cherry picked from commit af80fac425)
2025-11-12 12:40:02 +02:00
Miss Islington (bot)
75b5157e84
[3.14] gh-141311: Avoid assertion in BytesIO.readinto() (GH-141333) (GH-141457)
Fix error in assertion which causes failure if pos is equal to PY_SSIZE_T_MAX.
Fix undefined behavior in read() and readinto() if pos is larger that the size
of the underlying buffer.
(cherry picked from commit 7d54374f9c)

Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
2025-11-12 10:23:26 +00:00
Miss Islington (bot)
d6b4f4b10f
[3.14] gh-100218: correctly set errno when socket.if_{nametoindex,indextoname} raise OSError (GH-140905) (#141284)
gh-100218: correctly set `errno` when `socket.if_{nametoindex,indextoname}` raise `OSError` (GH-140905)

Previously, socket.if_nametoindex() and socket.if_indextoname() could raise
an `OSError` with a `None` errno. Now, the errno from libc is propagated.
(cherry picked from commit 3ce2d57b2f)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-11-09 13:11:43 +00:00
Serhiy Storchaka
1a080199af
[3.14] gh-140615: Update docstrings in the fcntl module (GH-140619) (GH-141231)
* Refer to bytes objects or bytes-like objects instead of strings.
* Remove backticks -- they do not have effect on formatting.
* Re-wrap lines to ensure the pydoc output fits in 80 columns.
(cherry picked from commit 610377056b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-11-08 11:16:45 +00:00
Victor Stinner
36e9f672f2
[3.14] Fix compiler warnings in remote debugging (#141060) (#141067)
Fix compiler warnings in remote debugging (#141060)

Example of fixed warnings on 32-bit Windows:

    Python\remote_debugging.c(24,53): warning C4244: 'function':
    conversion from 'uint64_t' to 'uintptr_t', possible loss of data

    Modules\_remote_debugging_module.c(789,44): warning C4244:
    'function': conversion from 'uint64_t' to 'size_t', possible loss
    of data

(cherry picked from commit f458ac01ba)
2025-11-05 19:49:39 +00:00
Miss Islington (bot)
8675f55f6a
[3.14] Fix a compiler warning in _randommodule.c (GH-141058) (#141063)
Fix a compiler warning in _randommodule.c (GH-141058)

The test just before the cast ensures that the cast cannot overflow.

Fix the warning on 32-bit Windows:

    Modules\_randommodule.c(525,28): warning C4244: '=': conversion
    from 'uint64_t' to 'Py_ssize_t', possible loss of data
(cherry picked from commit 4ac16dd109)

Co-authored-by: Victor Stinner <vstinner@python.org>
2025-11-05 19:10:32 +00:00
Miss Islington (bot)
267af29832
[3.14] gh-140979: Fix off-by-one error in the RE code validator (GH-140984) (GH-141001)
It was too lenient and allowed MARK opcodes with too large value.
(cherry picked from commit 1326d2a808)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-11-04 18:16:51 +02:00
Bénédikt Tran
bf2865f80f
[3.14] gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (GH-139234) (#139359)
* [3.14] gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (GH-139234)

Expose the XML Expat 2.7.2 mitigation APIs to disallow use of
disproportional amounts of dynamic memory from within an Expat
parser (see CVE-2025-59375 for instance).

The exposed APIs are available on Expat parsers, that is,
parsers created by `xml.parsers.expat.ParserCreate()`, as:

- `parser.SetAllocTrackerActivationThreshold(threshold)`, and
- `parser.SetAllocTrackerMaximumAmplification(max_factor)`.

(cherry picked from commit f04bea44c3)
(cherry picked from commit 68a1778b77)
2025-11-02 09:33:36 +00:00
Cody Maloney
9a7dccd7a1
[3.14] gh-140607: Validate returned byte count in RawIOBase.read (GH-140611) (#140728)
* [3.14] gh-140607: Validate returned byte count in RawIOBase.read (GH-140611)

While `RawIOBase.readinto` should return a count of bytes between 0 and
the length of the given buffer, it is not required to. Add validation
inside RawIOBase.read() that the returned byte count is valid.
(cherry picked from commit 0f0a362768)

Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Co-authored-by: Shamil <ashm.tech@proton.me>
Co-authored-by: Victor Stinner <vstinner@python.org>

* fixup: Use older attribute name

---------

Co-authored-by: Shamil <ashm.tech@proton.me>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-10-29 13:31:48 +01:00
Miss Islington (bot)
02604314ba
[3.14] GH-140590: Fix setstate for functools.partial C-module (GH-140671) (#140698)
GH-140590: Fix setstate for functools.partial C-module (GH-140671)

(cherry picked from commit d26686a7f8)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>
2025-10-28 18:15:27 +05:30
Miss Islington (bot)
84e01df175
[3.14] gh-134160: Add more comments for the xxlimited module (GH-140214) (GH-140664)
(cherry picked from commit 18e4a89e42)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-10-28 10:24:11 +01:00
Miss Islington (bot)
3bb0eb4ca9
[3.14] gh-140634: Fix a reference counting bug in os.sched_param.__reduce__() (GH-140667) (GH-140685)
(cherry picked from commit 364ae607d8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-10-27 20:08:57 +00:00
Sebastian Pipping
842c49b354
[3.14] gh-140593: Fix a memory leak in function my_ElementDeclHandler of pyexpat (GH-140602) (#140629)
[3.14] gh-140593: Fix a memory leak in function `my_ElementDeclHandler` of `pyexpat` (GH-140602)

Ensure that the memory allocated for the content model
passed to `my_ElementDeclHandler` is freed in all error
paths.

(cherry picked from commit e34a5e3304)
2025-10-26 15:19:18 +00:00
Miss Islington (bot)
96029bc472
[3.14] Remove unreachable break statements in _ctypes_test.c (GH-140585) (#140587)
Remove unreachable break statements in _ctypes_test.c (GH-140585)
(cherry picked from commit 2a1c9bd616)

Co-authored-by: Shamil <ashm.tech@proton.me>
2025-10-25 18:39:42 +03:00
Miss Islington (bot)
0fdae5f590
[3.14] gh-140474: Fix memory leak in array.array (GH-140478) (GH-140498)
gh-140474: Fix memory leak in `array.array` (GH-140478)
(cherry picked from commit aa9d0a61d5)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2025-10-23 10:20:16 +00:00
Miss Islington (bot)
01b52ea5c0
[3.14] gh-116738: Add critical section to dbm/gdbm context manager (gh-140391) (gh-140459)
(cherry picked from commit d51be28876)

Co-authored-by: Alper <alperyoney@fb.com>
2025-10-22 15:44:09 +00:00
Miss Islington (bot)
98d4c21c09
[3.14] gh-140398: fix memory leaks in readline module when PySys_Audit fails (GH-140400) (#140403)
gh-140398: fix memory leaks in `readline` module when `PySys_Audit` fails (GH-140400)
(cherry picked from commit e8e0f411ba)

Co-authored-by: Shamil <ashm.tech@proton.me>
2025-10-21 08:20:14 +00:00
Miss Islington (bot)
6493a6aaf3
[3.14] gh-140263: Fix data race in test_lock_two_threads (gh-140264) (gh-140369)
Clang-20 detects a data race between the unlock and the non-atomic
read of the lock state. Use a relaxed load for the assertion to avoid
the race.
(cherry picked from commit f11ec6e643)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2025-10-20 14:25:42 +00:00
Miss Islington (bot)
6cee144d3a
[3.14] gh-140306: Fix memory leaks in cross-interpreter data handling (GH-140307) (GH-140338)
(cherry picked from commit f9323213c9)

Co-authored-by: Shamil <ashm.tech@proton.me>
2025-10-19 19:53:36 +00:00
Miss Islington (bot)
128f48fd2d
[3.14] gh-140272: Fix memory leak in _gdbm.gdbm.clear() (GH-140274) (GH-140285)
(cherry picked from commit f937468e7c)

Co-authored-by: Shamil <ashm.tech@proton.me>
2025-10-18 13:17:42 +03:00
Miss Islington (bot)
32e60fa220
[3.14] gh-140120: Refresh HACL* to fix an hmac memory leak (GH-140188) (#140192)
gh-140120: Refresh HACL* to fix an hmac memory leak (GH-140188)

This pulls an updated version of HACL* that fixes the memory leak reported in GH-140120, via an upstream fix.
(cherry picked from commit 3a81313019)

Co-authored-by: Jonathan Protzenko <jonathan.protzenko+github@gmail.com>
2025-10-16 20:53:12 -07:00
Miss Islington (bot)
045e34964a
[3.14] gh-140061: Use _PyObject_IsUniquelyReferenced() to check if objects are uniquely referenced (gh-140062) (gh-140157)
The previous `Py_REFCNT(x) == 1` checks can have data races in the free
threaded build. `_PyObject_IsUniquelyReferenced(x)` is a more conservative
check that is safe in the free threaded build and is identical to
`Py_REFCNT(x) == 1` in the default GIL-enabled build.
(cherry picked from commit 32c264982e)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
2025-10-15 14:49:17 +00:00
Miss Islington (bot)
99e42ab49c
[3.14] gh-101828: Fix jisx0213 codecs removing null characters (gh-139340) (gh-140110)
gh-101828: Fix `jisx0213` codecs removing null characters (gh-139340)
(cherry picked from commit 87eadce3e0)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2025-10-14 14:36:05 +00:00
Sergey B Kirpichev
1c55b9163b
[3.14] gh-102431: Clarify constraints on operands of Decimal logical operations (GH-102836) (#140105)
* [3.14] gh-102431: Clarify constraints on operands of Decimal logical operations (GH-102836)

Sync C/Python implementation of the decimal: logical_ops for contexts.
(cherry picked from commit 6ecf77dbde)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-10-14 15:44:30 +02:00
Miss Islington (bot)
07eb67b859
[3.14] gh-127081: add critical sections to dbm objects (gh-132749) (#139996)
gh-127081: add critical sections to `dbm` objects (gh-132749)
(cherry picked from commit ffaeb3dddf)

Co-authored-by: Duane Griffin <duaneg@dghda.com>
2025-10-12 17:56:29 +05:30
Miss Islington (bot)
187588e675
[3.14] gh-139929: fix incorrect OpenSSL version-based guard in _ssl.c (GH-139945) (#139964)
gh-139929: fix incorrect OpenSSL version-based guard in `_ssl.c` (GH-139945)

fix OpenSSL version-based guards
(cherry picked from commit cdd3eee7fc)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-10-11 17:59:55 +00:00
Kumar Aditya
72f25a8d9a
[3.14] gh-139894: fix incorrect sharing of current task while forking in asyncio (GH-139897) (#139913)
* [3.14] gh-139894: fix incorrect sharing of current task while forking in `asyncio`  (GH-139897)

Fix incorrect sharing of current task with the forked child process by clearing thread state's current task and current loop in `PyOS_AfterFork_Child`.
(cherry picked from commit b881df47ff)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>

* Update Lib/test/test_asyncio/test_unix_events.py
2025-10-10 22:36:02 +05:30
Kumar Aditya
926d734840
[3.14] gh-116738: make mmap module thread-safe (GH-139237) (#139825)
* [3.14] gh-116738: make `mmap` module thread-safe (GH-139237)
(cherry picked from commit 7f155f9c46)

Co-authored-by: Alper <alperyoney@fb.com>
2025-10-09 20:19:03 +05:30
Kumar Aditya
90cd009209
[3.14] gh-139748: fix leaks in AC error paths when using unicode FS-b… (#139789)
* [3.14] 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:16:21 +05:30
Dino Viehland
81dc8b12f0
[3.14] gh-139525: Don't specialize functions which have a modified vectorcall (GH-139524) (#139709)
Don't specialize functions which have a modified vectorcall
2025-10-08 09:13:34 -07:00
Miss Islington (bot)
ea1ed82fed
[3.14] gh-139774: use relaxed atomics for datetime hashes (GH-139775) (#139780)
gh-139774: use relaxed atomics for datetime hashes (GH-139775)
(cherry picked from commit 49fb46f555)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-10-08 21:09:09 +05:30
Miss Islington (bot)
fb223e691e
[3.14] GH-137573: Add test to check that the margin used for overflow protection is larger than the stack space used by the interpreter (GH-137724) (GH-139295)
(cherry picked from commit 16eae6d90d)

Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-10-08 14:44:16 +02:00
Miss Islington (bot)
5579708b1c
[3.14] gh-60462: Fix locale.strxfrm() on Solaris (GH-138242) (GH-138448)
It should interpret the result of wcsxfrm() as a sequence of abstract
integers, not a sequence of Unicode code points or using other encoding
scheme that does not preserve ordering.
(cherry picked from commit 482fd0c811)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-10-08 14:34:51 +02:00
Miss Islington (bot)
4e8f5e65eb
[3.14] gh-137490: Fix signal.sigwaitinfo() on NetBSD (GH-137523) (GH-138935)
Handle ECANCELED in the same way as EINTR to work around the Posix
violation in the NetBSD's implementation.
(cherry picked from commit 07d0b95b05)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-10-08 14:33:30 +02:00
Miss Islington (bot)
0188e0fd38
[3.14] gh-137986: Fix and improve the csv functions docstrings (GH-137987) (GH-138107)
The csv.register_dialect() docstring no longer imply that it returns a dialect.
All functions have now signatures.
(cherry picked from commit aa1dbd4dde)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: maurycy <5383+maurycy@users.noreply.github.com>
2025-10-08 14:27:57 +02:00
Miss Islington (bot)
d424344ce9
[3.14] bpo-41839: Fix error checking in sched_get_priority_ functions (GH-22374) (GH-138201)
(cherry picked from commit bbcb75c986)

Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
2025-10-08 14:26:59 +02:00
Miss Islington (bot)
669253fde5
[3.14] gh-138204: Forbid expansion of a shared anonymous mmap on Linux (GH-138220) (GH-138386)
This is a Linux kernel bug which caused a bus error.
https://bugzilla.kernel.org/show_bug.cgi?id=8691
(cherry picked from commit 33fcb0c4a0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-10-08 14:26:09 +02:00
Serhiy Storchaka
9ec4e3838a
[3.14] gh-138264: Fix gcc 14 compiler warnings (GH-138265) (GH-138426)
(cherry picked from commit 4a33077fdb)
2025-10-07 22:26:05 +02:00
Stan Ulbrych
537b558ce9
[3.14] gh-137920: Fix semantically relevant typo in curses.window.attron (#137940) (GH-138506)
Originally authored by: vict-Yang

(cherry picked from commit ce70a57bc0)
2025-10-07 22:21:41 +02:00
Miss Islington (bot)
fff26500e5
[3.14] gh-130567: Fix possible crash in locale.strxfrm() (GH-138940) (GH-139265)
On some macOS versions there was an off-by-one error in wcsxfrm() which
caused writing past the end of the array if its size was not calculated
by running wcsxfrm() first.

(cherry picked from commit 5854cf38a2)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-10-07 21:54:04 +02:00
Miss Islington (bot)
cde02ae782
[3.14] gh-139283: correctly handle size limit in cursor.fetchmany() (GH-139296) (GH-139441)
Passing a negative or zero size to `cursor.fetchmany()` made it fetch all rows
instead of none.

While this could be considered a security vulnerability, it was decided to treat
this issue as a regular bug as passing a non-sanitized *size* value in the first
place is not recommended.
(cherry picked from commit bc172ee830)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-10-07 21:23:08 +02:00
Miss Islington (bot)
2f14d23013
[3.14] gh-139210: Fix use-after-free in xml.etree.ElementTree.iterparse() (GH-139211) (GH-139455)
(cherry picked from commit c86eb4d3ac)

Co-authored-by: Ken Jin <kenjin@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-10-07 21:13:27 +02:00
Miss Islington (bot)
ffc67b3505
[3.14] gh-138004: Fix setting a thread name on OpenIndiana (GH-138017) (#138384)
gh-138004: Fix setting a thread name on OpenIndiana (GH-138017)

Encode Solaris/Illumos thread names to ASCII, since
OpenIndiana does not support non-ASCII names.

Add tests for setting non-ASCII name for the main thread.
(cherry picked from commit c19db1d2b8)

Co-authored-by: jadonduff <jadon_duff@icloud.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-10-07 20:58:35 +02:00
Miss Islington (bot)
4429554223
[3.14] gh-116738: make cProfile module thread-safe (GH-138229) (#138575)
gh-116738: make `cProfile` module thread-safe (GH-138229)
(cherry picked from commit 8554c0917e)

Co-authored-by: Alper <alperyoney@fb.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-10-07 18:51:22 +00:00