Commit graph

14491 commits

Author SHA1 Message Date
Miss Islington (bot)
61a24ea572
[3.13] gh-137109: refactor warning about threads when forking (GH-141438) (GH-141614) (GH-141639)
[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.
(cherry picked from commit 0d8fb0b852)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
2025-11-16 19:26:34 -08:00
Miss Islington (bot)
83bd8689aa
[3.13] gh-124111: Fix TCL 9 thread detection (GH-141483)
(cherry picked from commit dc0987080e)

Co-authored-by: Michael Cho <michael@michaelcho.dev>
2025-11-12 22:44:01 +00:00
Cody Maloney
7c62bd571b
[3.13] gh-141311: Avoid assertion in BytesIO.readinto() (GH-141333) (GH-141478)
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)
2025-11-12 23:37:06 +02:00
Miss Islington (bot)
18b883b9e9
[3.13] gh-132657: add regression test for PySet_Contains with unhashable type (GH-141411) (#141467)
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 21:12:18 +05:30
Mohsin Mehmood
8402c28f11
[3.13] gh-141314: Fix TextIOWrapper.tell() assertion failure with standalone carriage return (GH-141331) (GH-141452)
The assertion was checking wrong variable (skip_back vs skip_bytes).
(cherry picked from commit af80fac425)
2025-11-12 12:40:14 +02:00
Bénédikt Tran
873f0d023c
[3.13] gh-100218: correctly set errno when socket.if_{nametoindex,indextoname} raise OSError (GH-140905) (#141285)
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)
2025-11-09 13:31:49 +00:00
Serhiy Storchaka
731832a024
[3.13] gh-140615: Update docstrings in the fcntl module (GH-140619) (GH-141231) (GH-141232)
* 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)
(cherry picked from commit 1a080199af)
2025-11-08 11:50:17 +00:00
Miss Islington (bot)
3ecf63754e
[3.13] Fix a compiler warning in _randommodule.c (GH-141058) (#141064)
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:08:41 +00:00
Miss Islington (bot)
fd9be78f4e
[3.13] gh-140979: Fix off-by-one error in the RE code validator (GH-140984) (GH-141000)
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:40 +02:00
Sebastian Pipping
bc36bd1786
[3.13] gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (GH-139234) (#139367)
* gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (#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 12:39:11 +00:00
Cody Maloney
a1a71efa6e
[3.13] gh-140607: Validate returned byte count in RawIOBase.read (GH-140611) (#140730)
* [3.13] 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:57 +01:00
Miss Islington (bot)
bec053c184
[3.13] GH-140590: Fix setstate for functools.partial C-module (GH-140671) (#140699)
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:14:14 +05:30
Miss Islington (bot)
9c8eade20c
[3.13] gh-140634: Fix a reference counting bug in os.sched_param.__reduce__() (GH-140667) (GH-140686)
(cherry picked from commit 364ae607d8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-10-27 20:05:10 +00:00
Sebastian Pipping
7abbf51839
[3.13] gh-140593: Fix a memory leak in function my_ElementDeclHandler of pyexpat (GH-140602) (#140630)
[3.13] 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:22:20 +00:00
Miss Islington (bot)
01f9c51caa
[3.13] Remove unreachable break statements in _ctypes_test.c (GH-140585) (#140588)
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:54 +03:00
Miss Islington (bot)
640bc258c1
[3.13] gh-140474: Fix memory leak in array.array (GH-140478) (GH-140499)
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 12:18:01 +00: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
0231a391f9
[3.13] gh-140272: Fix memory leak in _gdbm.gdbm.clear() (GH-140274) (GH-140289)
(cherry picked from commit f937468e7c)

Co-authored-by: Shamil <ashm.tech@proton.me>
2025-10-18 11:00:10 +00:00
Stan Ulbrych
c5ec267311
[3.13] gh-101828: Fix jisx0213 codecs removing null characters (gh-139340) (gh-140112)
* [3.13] 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>

* Accidentally removed line
2025-10-14 14:48:29 +00:00
Sergey B Kirpichev
bfb9639352
[3.13] gh-102431: Clarify constraints on operands of Decimal logical operations (GH-102836) (#140106)
* [3.13] 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:45:02 +02:00
Victor Stinner
7b49ec784a
[3.13] gh-139748: Fix socket.if_nametoindex() Argument Clinic (#139815)
gh-139748: Fix socket.if_nametoindex() Argument Clinic

Fix a reference leak.
2025-10-08 23:24:30 +00: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
Stan Ulbrych
0404ca7201
[3.13] gh-137920: Fix semantically relevant typo in curses.window.attron (GH-137940) (GH-138507)
Originally authored by: vict-Yang

(cherry picked from commit ce70a57bc0)
2025-10-07 22:22:18 +02:00
Bénédikt Tran
7bb51bd5be
[3.13] gh-139283: correctly handle size limit in cursor.fetchmany() (GH-139296) (#139444)
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)
2025-10-07 13:33:40 +02:00
Miss Islington (bot)
be8f3a68f4
[3.13] gh-139327: fix some reference leaks in sqlite3 error branches (GH-139328) (#139472)
(cherry picked from commit d0a3eff9d6)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-10-07 13:32:51 +02:00
Sebastian Pipping
69ab8fbb85
[3.13] gh-139400: Make sure that parent parsers outlive their subparsers in pyexpat (GH-139403) (GH-139608)
Within libexpat, a parser created via `XML_ExternalEntityParserCreate`
is relying on its parent parser throughout its entire lifetime.
Prior to this fix, is was possible for the parent parser to be
garbage-collected too early.

(cherry picked from commit 6edb2ddb5f)
2025-10-06 15:17:37 +02:00
Miss Islington (bot)
f48128b6b3
[3.13] gh-139210: Fix use-after-free in xml.etree.ElementTree.iterparse() (GH-139211) (GH-139456)
(cherry picked from commit c86eb4d3ac)

Co-authored-by: Ken Jin <kenjin@python.org>
2025-09-30 18:14:44 +00:00
Miss Islington (bot)
a461f25ce6
[3.13] gh-139312: Update bundled libexpat to 2.7.3 (GH-139319) (#139377)
gh-139312: Update bundled libexpat to 2.7.3 (GH-139319)

+ Blurb
+ Update sbom.spdx.json
(cherry picked from commit 48d0d0dd97)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2025-09-27 08:19:09 +00:00
Miss Islington (bot)
d1f6b392e4
[3.13] gh-130567: Fix possible crash in locale.strxfrm() (GH-138940) (GH-139266)
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>
2025-09-24 13:48:08 +02:00
Petr Viktorin
135198dd5d
[3.13] gh-138008: Fix segfaults in _ctypes due to invalid argtypes (GH-138285) (#138746)
(cherry picked from commit 1ce05537a3)

Signed-off-by: Nguyen Viet Dung <29406816+magnified103@users.noreply.github.com>
Signed-off-by: Nguyen Viet Dung <dung@ekluster.com>
Co-authored-by: Dung Nguyen <dung@ekluster.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Yongzi Li <204532581+Yzi-Li@users.noreply.github.com>
2025-09-18 12:46:05 +01:00
Miss Islington (bot)
ccf4b3e021
[3.13] gh-138998: Upgrade vendored expat to 2.7.2 (GH-138999) (#139025)
(cherry picked from commit 64c876dd68)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2025-09-18 12:42:42 +01:00
Erlend E. Aasland
5f84c1d192
[3.13] gh-138736: Fix sqlite3.Connection.blobopen 'row' parameter type and naming (#138738) (#139063)
The 'row' parameter represents a ROWID. Clarify this in docs and docstrings.

(cherry picked from commit 8eb106240f)

Co-authored-by: chiri <chirizxc@proton.me>
2025-09-17 16:26:10 +00:00
Miss Islington (bot)
d8b3a83cf2
[3.13] gh-137490: Fix signal.sigwaitinfo() on NetBSD (GH-137523) (GH-138936)
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-09-15 16:43:32 +00:00
Miss Islington (bot)
dbe5e3925b
[3.13] gh-138779: Use the dev_t converter for st_rdev (GH-138780) (GH-138927)
This allows to support device numbers larger than 2**63-1.
(cherry picked from commit 43013f72f0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-09-15 14:29:57 +00:00
Miss Islington (bot)
7160f9f5d8
[3.13] gh-137017: Ensure Thread.is_alive() only returns False after the underlying OS thread exits (gh-137315) (gh-138917)
(cherry picked from commit aa9ceb1721)

Co-authored-by: Abdul <abdulrasheedibrahim47@gmail.com>
Co-authored-by: Sam Gross <colesbury@gmail.com>
2025-09-15 14:28:05 +01:00
Miss Islington (bot)
6aa7fa0625
[3.13] gh-138659: Typo in the gc module docstring (GH-138660) (#138663)
gh-138659: Typo in the gc module docstring (GH-138660)

docs(gc): fix typo in get_threshold() docstring

Removes a duplicate "the" from the docstring for the `gc.get_threshold()` function.
(cherry picked from commit c006a623e7)

Co-authored-by: Aalaap Dey <65075436+axdeyy@users.noreply.github.com>
2025-09-08 14:39:43 +00:00
Miss Islington (bot)
837df2774f
[3.13] fix comment reference from man 7 signal to man 7 signal-safety (GH-138554) (#138595)
fix comment reference from man 7 signal to man 7 signal-safety (GH-138554)
(cherry picked from commit 2f5ace780b)


docs: fix comment reference from man 7 signal to man 7 signal-safety

Co-authored-by: mqudah <mohghq@gmail.com>
2025-09-06 19:02:33 +00:00
Bénédikt Tran
afec2c70eb
[3.13] gh-116946: fully implement GC protocol for _curses_panel.panel (GH-138333) (#138428)
[3.14] gh-116946: fully implement GC protocol for `_curses_panel.panel` (GH-138333)

This commit fixes possible reference loops via `panel.set_userptr`
by implementing `tp_clear` and `tp_traverse` for panel objects.
(cherry picked from commit 572df47840)
2025-09-06 12:17:57 +02:00
Miss Islington (bot)
a7fd73e43f
[3.13] gh-60462: Fix locale.strxfrm() on Solaris (GH-138242) (GH-138449)
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-09-03 13:31:23 +00:00
Miss Islington (bot)
06dbf81a56
[3.13] gh-138204: Forbid expansion of a shared anonymous mmap on Linux (GH-138220) (GH-138387)
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-09-03 11:33:08 +03:00
Bénédikt Tran
a38f0266df
[3.13] gh-116946: Revert GC protocol for immutable empty heap types (GH-138322, GH-138323, GH-138326) (#138337)
* Revert "[3.13] gh-116946: fully implement GC protocol for `bz2` objects (GH-138266) (#138322)"

This reverts commit 90036f51fe.

* Revert "[3.13] gh-116946: fully implement GC protocol for `lzma` objects (GH-138288) (#138323)"

This reverts commit 828682df86.

* Revert "[3.13] gh-116946: fully implement GC protocol for `_hashlib` objects (GH-138289) (#138326)"

This reverts commit 21b593219a.
2025-09-01 21:14:47 +05:30
Bénédikt Tran
d25d2d6b95
[3.13] gh-116946: fully implement GC protocol for zlib objects (GH-138290) (#138328)
(cherry picked from commit 2a54acf3c3)
2025-09-01 12:25:11 +02:00
Bénédikt Tran
21b593219a
[3.13] gh-116946: fully implement GC protocol for _hashlib objects (GH-138289) (#138326)
(cherry picked from commit 6f1dd9551a)
2025-09-01 12:23:28 +02:00
Bénédikt Tran
828682df86
[3.13] gh-116946: fully implement GC protocol for lzma objects (GH-138288) (#138323)
(cherry picked from commit 3ea16f990f)
2025-09-01 12:22:06 +02:00
Bénédikt Tran
90036f51fe
[3.13] gh-116946: fully implement GC protocol for bz2 objects (GH-138266) (#138322)
(cherry picked from commit 9be91f6a20)
2025-09-01 12:21:40 +02:00
Miss Islington (bot)
502ca0d1ad
[3.13] bpo-41839: Fix error checking in sched_get_priority_ functions (GH-22374) (GH-138202)
(cherry picked from commit bbcb75c986)

Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
2025-08-27 18:05:36 +00:00
Serhiy Storchaka
59068dfcf4
[3.13] gh-137986: Fix and improve the csv functions docstrings (GH-137987) (GH-138108)
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: maurycy <5383+maurycy@users.noreply.github.com>
2025-08-24 08:37:41 +00:00
Gregory P. Smith
9face218e7
[3.13] gh-87135: Hang non-main threads that attempt to acquire the GIL during finalization (GH-105805) (GH-137827)
* [3.13] gh-87135: Hang non-main threads that attempt to acquire the GIL during finalization (GH-105805)

Instead of surprise crashes and memory corruption, we now hang threads that attempt to re-enter the Python interpreter after Python runtime finalization has started. These are typically daemon threads (our long standing mis-feature) but could also be threads spawned by extension modules that then try to call into Python. This marks the `PyThread_exit_thread` public C API as deprecated as there is no plausible safe way to accomplish that on any supported platform in the face of things like C++ code with finalizers anywhere on a thread's stack. Doing this was the least bad option.

(cherry picked from commit 8cc5aa47ee)

Co-authored-by: Jeremy Maitin-Shepard <jeremy@jeremyms.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>

* state "3.13.7 and earlier"
* backport: do not add the deprecated marker
* fix Py_IsFinalizing doc ref

---------

Co-authored-by: Jeremy Maitin-Shepard <jeremy@jeremyms.com>
2025-08-17 09:08:14 -07:00
Peter Bierma
da39cb9716
[3.13] gh-137583: Only lock the SSL context, not the SSL socket (GH-137588) (GH-137613)
Fixes a deadlock introduced in 3.13.6.

(cherry picked from commit 55788a9096)
2025-08-11 22:05:13 -04:00
Miss Islington (bot)
8905f7a99b
[3.13] gh-137044: Support large limit values in getrlimit() and setrlimit() (GH-137338) (GH-137507)
* Return large limit values as positive integers instead of negative integers
  in resource.getrlimit().
* Accept large values and reject negative values (except RLIM_INFINITY)
  for limits in resource.setrlimit().
(cherry picked from commit baefaa6cba)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-08-07 09:37:02 +00:00