14522 Commits

Author SHA1 Message Date
Victor Stinner
3df9e31142
[3.13] gh-144100: Fix crash for POINTER(str) used in ctypes argtypes (#144108) (#144245)
gh-144100: Fix crash for POINTER(str) used in ctypes argtypes (#144108)


(cherry picked from commit 8f459255eba2b6639f1912e5c5e318a7cdafada1)

Co-authored-by: VanshAgarwal24036 <148854295+VanshAgarwal24036@users.noreply.github.com>
2026-01-27 12:59:55 +01:00
Stan Ulbrych
837b88fd9f
[3.13] gh-144023: Prevent follow_symlinks from being allowed with an fd of 0 (GH-144022) (#144152)
[3.13] gh-144023: Prevent follow_symlinks from being allowed with an fd of 0 (GH-144022)

The check was (fd > 0), should be (fd >= 0).
(cherry picked from commit fa44efa0ef1972ac1e2f66996303154be11f605e)

Co-authored-by: AZero13 <gfunni234@gmail.com>
2026-01-22 15:52:49 +00:00
Miss Islington (bot)
640ef9931e
[3.13] Update struct.__doc__: _Bool available unconditionally (GH-143716) (#144071)
Update struct.__doc__: _Bool available unconditionally (GH-143716)

This amends commit a9296e7f3be4d6c22271b25c86467ff867c63bbb.
(cherry picked from commit 31c81ab0a2fb7009a76426617991a9b539ab0180)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2026-01-20 12:32:45 +00:00
Miss Islington (bot)
be602fcde6
[3.13] gh-143249: Fix buffer leak when overlapped operation fails to start on windows (GH-143250) (#143796)
gh-143249: Fix buffer leak when overlapped operation fails to start on windows (GH-143250)
(cherry picked from commit 103a384bfdeafc68ab39ea9bf8838a8b2eec83dd)

Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
2026-01-13 13:53:41 +00:00
Miss Islington (bot)
8b7ebbb432
[3.13] gh-143544: Fix possible use-after-free in the JSON decoder when JSONDecodeError disappears during raising it (GH-143561) (#143734)
gh-143544: Fix possible use-after-free in the JSON decoder when JSONDecodeError disappears during raising it (GH-143561)
(cherry picked from commit c3157480601499565fd42a8afbdb0207328ac484)

Co-authored-by: VanshAgarwal24036 <148854295+VanshAgarwal24036@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-01-12 16:02:23 +00:00
Sergey B Kirpichev
8fd4435cd9
[3.13] gh-78724: Raise RuntimeError's when calling methods on non-ready Struct()'s (GH-143643) (GH-143714)
(cherry picked from commit 515ae4078dffa0b74e5e5431462c2f4fe4563ffa)
2026-01-12 14:45:52 +02:00
Serhiy Storchaka
1822f59dc7
[3.13] gh-142881: Fix concurrent and reentrant call of atexit.unregister() (GH-142901) (GH-143722)
(cherry picked from commit dbd10a6c29ba1cfc9348924a090b5dc514470002)
2026-01-12 10:05:09 +00:00
Serhiy Storchaka
dcc6117628
[3.13] gh-143378: Fix use-after-free when BytesIO is concurrently mutated during write operations (GH-143408) (GH-143600)
PyObject_GetBuffer() can execute user code (e.g. via __buffer__), which may
close or otherwise mutate a BytesIO object while write() or writelines()
is in progress. This could invalidate the internal buffer and lead to a
use-after-free.

Ensure that PyObject_GetBuffer() is called before validation checks.
(cherry picked from commit 6d54b6ac7d5744e1f59d784c8e020d632d2959a3)

Co-authored-by: zhong <60600792+superboy-zjc@users.noreply.github.com>
2026-01-12 10:37:28 +02:00
Serhiy Storchaka
e319262c4e
[3.13] gh-143638: Forbid cuncurrent use of the Pickler and Unpickler objects in C implementation (GH-143664) (GH-143687)
Previously, this could cause crash or data corruption, now concurrent calls
of methods of the same object raise RuntimeError.
(cherry picked from commit d1282efb2b847bf9274d78c5f15ea00499b2c894)
2026-01-11 12:34:36 +00:00
Victor Stinner
43e495d6f4
[3.13] gh-142991: Fix socketmodule.c build: remove _Py_FALLTHROUGH (#143514)
Fix commit 7f936694dbc0dc0dbb07d98fa668776c4e4ca595 backport which
uses _Py_FALLTHROUGH: this macro only exists in Python 3.14 and
newer.
2026-01-07 14:17:06 +00:00
Miss Islington (bot)
7f936694db
[3.13] gh-142991: socketmodule: fixed getsockaddrlen() for PF_DIVERT socket (GH-142993) (#143482)
gh-142991: socketmodule: fixed getsockaddrlen() for PF_DIVERT socket (GH-142993)
(cherry picked from commit 05406b221dc9d5946c60253392788d60f1f08c8b)

Co-authored-by: Gleb Smirnoff <glebius@FreeBSD.org>
2026-01-06 16:48:03 +00:00
Semyon Moroz
97694de41e
[3.13] gh-143331: Schedule to remove format "N" for Decimal (GH-143372) (#143477)
(cherry picked from commit dd750b348501247d458ea8d454213d4959a8f8b9)
2026-01-06 14:02:32 +00:00
Bénédikt Tran
44bdb833d1
[3.13] gh-143309: fix UAF in os.execve when the environment is concurrently mutated (GH-143314) (#143431)
[3.13] gh-143309: fix UAF in `os.execve` when the environment is concurrently mutated (GH-143314) (#143431)

(cherry picked from commit 9609574e7fd36edfaa8b575558a82cc14e65bfbc)
(cherry picked from commit c99f7667436d8978b4077704333e2a351f2a026f)
2026-01-05 19:56:02 +01:00
Miss Islington (bot)
2b8ac2c3da
[3.13] gh-143308: fix UAF when PickleBuffer is concurrently mutated in a callback (GH-143312) (#143397)
gh-143308: fix UAF when PickleBuffer is concurrently mutated in a callback (GH-143312)
(cherry picked from commit 6c53af18f61c074d514e677b469b6201573a59da)

---------------

Co-authored-by: Aaron Wieczorek <aaronw@fastmail.com>
Co-authored-by: Aaron Wieczorek <woz@Aarons-MacBook-Pro.local>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-01-03 23:53:59 +00:00
Miss Islington (bot)
b40bf5ffc8
[3.13] gh-143310: fix crash in Tcl object conversion with concurrent mutations (GH-143321) (#143344)
gh-143310: fix crash in Tcl object conversion with concurrent mutations (GH-143321)
(cherry picked from commit 9712dc1d9eb03ffa96ed746d20bd43239d251ba7)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-01-02 10:12:57 +00:00
Bénédikt Tran
afa24d8324
[3.13] gh-142830: prevent some crashes when mutating sqlite3 callbacks (GH-143245) (#143323)
(cherry picked from commit 7f6c16a956d598663d8c67071c492f197045d967)
2026-01-01 11:22:50 +00:00
Miss Islington (bot)
93cb42fcb9
[3.13] gh-143200: fix UAFs in Element.__{set,get}item__ when the element is concurrently mutated (GH-143226) (#143274)
gh-143200: fix UAFs in `Element.__{set,get}item__` when the element is concurrently mutated (GH-143226)
(cherry picked from commit b6b0e14b3d4aa9e9b89bef9a516177238883e1a7)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-12-29 18:15:28 +00:00
Miss Islington (bot)
5624bf9758
[3.13] gh-143145: Fix possible reference leak in ctypes _build_result() (GH-143131) (GH-143170)
The result tuple was leaked if __ctypes_from_outparam__() failed for any item.
(cherry picked from commit 579c5b496b467a2b175cb30caa4f6873cb13c9a1)

Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
2025-12-25 19:09:39 +02:00
Miss Islington (bot)
4dd9d94619
[3.13] gh-143004: Fix possible use-after-free in collections.Counter.update() (GH-143044) (GH-143167)
This happened when the Counter was mutated when incrementing
the value for an existing key.
(cherry picked from commit 86d904588e8c84c7fccb8faf84b343f03461970d)

Co-authored-by: kaushal trivedi <155625932+Kaushalt2004@users.noreply.github.com>
2025-12-25 13:41:24 +02:00
Miss Islington (bot)
a9a8ca3e47
[3.13] gh-122431: Correct the non-negative error message in readline.append_history_file (GH-143075) (GH-143091)
gh-122431: Correct the non-negative error message in `readline.append_history_file` (GH-143075)

"positive" -> "non-negative", since zero is included.
(cherry picked from commit a273bc99d2ff853f59ee6da4d897b1be72a03975)

Co-authored-by: Zheng Yu <dataisland@outlook.com>
2025-12-23 04:59:43 +00:00
Miss Islington (bot)
98d97d76a8
[3.13] gh-143012: use Py_ssize_t cast for PyBytes_FromStringAndSize (GH-143013) (#143015)
gh-143012: use `Py_ssize_t` cast for `PyBytes_FromStringAndSize` (GH-143013)
(cherry picked from commit 5989095dfd08735525f2b615066bc3c231b09388)

Co-authored-by: AZero13 <gfunni234@gmail.com>
2025-12-20 07:59:55 +00:00
Serhiy Storchaka
08d665d607
[3.13] gh-112127: Fix possible use-after-free in atexit.unregister() (GH-114092) (GH-142880)
(cherry picked from commit 2b466c47c333106dc9522ab77898e6972e25a2c6)

Co-authored-by: Benjamin Johnson <ben332004@gmail.com>
2025-12-17 17:15:21 +00:00
Miss Islington (bot)
53ca3b7b5c
[3.13] Fix os.posix_spawn() error handling (GH-142532) (#142581)
Fix os.posix_spawn() error handling (GH-142532)

Consistently use `goto exit;` in `py_posix_spawn()`.
(cherry picked from commit 8cfa351560487d472df4c7d841814801fbf57397)

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2025-12-17 15:43:51 +00:00
Miss Islington (bot)
88b8e63c54
[3.13] gh-142783: Fix possible use after free in zoneinfo module (GH-142790) (GH-142861)
(cherry picked from commit 8307a14d0edc14ae2f775995720e4b6d6dc865b3)

Co-authored-by: wangxiaolei <fatelei@gmail.com>
2025-12-17 09:21:20 +00:00
Serhiy Storchaka
9361207bc2
[3.13] gh-142495: Make defaultdict keep existed value when racing with __missing__ (GH-142668) (GH-142858)
(cherry picked from commit a0434075108efe6acdfba34f42545f4d80ac9a5e)

Co-authored-by: Edward Xu <xuxiangad@gmail.com>
2025-12-17 08:40:47 +00:00
Miss Islington (bot)
4480f5b661
[3.13] gh-142595: Amend be5e0dcdedb (fix NULL pointer dereference) (GH-142775) (GH-142789)
(cherry picked from commit 15a9762500b3d9a13206aa54d8695513efaf3b55)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-12-16 13:00:40 +02:00
Cody Maloney
affd2f2ff2
[3.13] gh-142594: fix by property calls io.TextIOWrapper.detach (GH-142706) (GH-142757)
(cherry picked from commit 1d3854a19a376c1fc7f71e96c620f6bc2de8cd74)

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: yihong <zouzou0208@gmail.com>
2025-12-16 10:55:35 +01:00
Miss Islington (bot)
f66684969e
[3.13] gh-142595: add type check for namedtuple call during decimal initialization (GH-142608) (GH-142622)
(cherry picked from commit be5e0dcdedb63185aaa3e2f711d14dc828cb3640)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-12-15 15:04:11 +01:00
Prithviraj Chaudhuri
2d05a0cc2e
[3.13] gh-140042: Removing unsafe call to sqlite3_shutdown (GH-141793) (#141812) 2025-11-30 14:33:05 +02:00
Miss Islington (bot)
66e2b4ac54
[3.13] gh-141801: Use accessors for ASN1_STRING fields in libssl (GH-141802) (#141848)
gh-141801: Use accessors for ASN1_STRING fields in libssl (GH-141802)

* gh-141801: Use accessors for ASN1_STRING fields

While ASN1_STRING is currently exposed, it is better to use the
accessors. See https://github.com/openssl/openssl/issues/29117 where, if
the type were opaque, OpenSSL's X509 objects could be much more
memory-efficient.

* Update Modules/_ssl.c



* Update Modules/_ssl.c



---------
(cherry picked from commit c41fce08a5d7aae8fd9e3fa25e0ba521600e097c)

Co-authored-by: David Benjamin <davidben@davidben.net>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-11-22 10:53:14 -08:00
Hugo van Kemenade
af94f62bf6
[3.13] gh-141659: Fix bad file descriptor error in subprocess on AIX (GH-141660) (#141828)
Co-authored-by: Ayappan Perumal <ayappap2@in.ibm.com>
2025-11-21 18:10:01 +00:00
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 0d8fb0b8523769e24f249d19dab3781a10b50e8b)

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 dc0987080ed66c662e8e0b24cdb8c179817bd697)

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 7d54374f9c7d91e0ef90c4ad84baf10073cf1d8a)
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 2ac738d325a6934e39fecb097f43d4d4ed97a2b9)

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 af80fac42548719ede7241bfbab3c2c0775b4760)
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 3ce2d57b2f02030353af314d89c5f6215d2f5c96)
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 610377056bad696915d70590429e68002bee9006)
(cherry picked from commit 1a080199aff6d98b476ab19e409d7ca4d56cb3c6)
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 4ac16dd10950fad2d3e58e8b0ba5f2e621af3cc1)

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 1326d2a808245e5f2de9e515460bab30556e8f05)

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 f04bea44c37793561d753dd4ca6e7cd658137553)
(cherry picked from commit 68a1778b7721f3fb853cd3aa674f7039c2a4df36)
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 0f0a362768aecb4c791724cce486d8317533a94d)

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 d26686a7f87d63499f7296c0811fa0535637a93b)

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 364ae607d8035db8ba92486ebebd8225446c1a90)

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 e34a5e33049ce845de646cf24a498766a2da3586)
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 2a1c9bd616b1b3a07c74d280e3f7e2bd94d0cc22)

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 aa9d0a61d5c48717454f36351f0aabe4cc532de5)

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 f9323213c98c9f1f7f3bf5af883b73047432fe50)

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 f937468e7c88c768a28ff4e653da051ffa30d86c)

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 87eadce3e0309d80a95e85d70a00028b5dca9907)

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

* Accidentally removed line
2025-10-14 14:48:29 +00:00