Commit graph

33112 commits

Author SHA1 Message Date
Bénédikt Tran
e102378eca
[3.13] gh-142516: fix reference leaks in ssl.SSLContext objects (GH-143685) (GH-145075) (#148371)
Cherry picked from commits 3a2a686cc4
and 1decc7ee20 with minor amendments.
2026-05-24 11:43:03 +02:00
Hai Zhu
5d03b24827
[3.13] gh-148450: abc.register needs to update type_version when tp_flags is changed (GH-148623) (#150307) 2026-05-23 17:20:16 +05:30
Miss Islington (bot)
cfa3daa7fe
[3.13] gh-107398: Fix tarfile stream mode exception when process the file with the gzip extra field (GH-126304) (GH-150201)
(cherry picked from commit 65f99329ed)

Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-05-21 22:38:54 +03:00
sobolevn
32feeff72d
[3.13] gh-150146: Fix NULL dereference in _Py_subs_parameters (GH-150147) (#150155)
* [3.13] gh-150146: Fix NULL dereference in `_Py_subs_parameters` (GH-150147)
(cherry picked from commit f621ba16b7)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-05-20 14:04:17 +00:00
Shamil
e87baa8d24
[3.13] gh-142831: Fix use-after-free in json encoder during re-entrant mutation (gh-142851) (#150079)
gh-142831: Fix use-after-free in json encoder during re-entrant mutation (gh-142851)

User callbacks invoked during JSON encoding (e.g. the `default` callback or
a custom string encoder) can mutate or clear the dict or sequence being
encoded, invalidating borrowed references to items, keys, and values. Hold
strong references unconditionally while iterating.



(cherry picked from commit 235fa7244a)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2026-05-19 20:33:22 -07:00
Miss Islington (bot)
9e071c9b28
[3.13] gh-146211: Reject CR/LF in HTTP tunnel request headers (GH-146212) (#148343)
gh-146211: Reject CR/LF in HTTP tunnel request headers (GH-146212)
(cherry picked from commit 05ed7ce7ae)

Co-authored-by: Seth Larson <seth@python.org>
Co-authored-by: Illia Volochii <illia.volochii@gmail.com>
2026-05-18 19:44:36 +02:00
Miss Islington (bot)
b2b35bad02
[3.13] gh-149916: Restore the commented out part of test_body_encode in test_email (GH-149917) (GH-149939)
(cherry picked from commit 1cbe035723)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-05-17 08:29:33 +00:00
Miss Islington (bot)
a6ebca755c
[3.13] gh-148821: Add more tests for invalid XML encodings (GH-149820) (GH-149823)
(cherry picked from commit c6f7368157)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-05-14 10:34:45 +00:00
Miss Islington (bot)
82db654e13
[3.13] gh-128110: Fix rfc2047 whitespace handling in email parser address headers (GH-130749) (#149789)
RFC 2047 Section 6.2 requires that "any 'linear-white-space' that
separates a pair of adjacent 'encoded-word's is ignored." The modern
header value parser correctly implements that for unstructured headers,
but had missed a case in structured headers. This could cause a parsed
address header to include extraneous spaces in a display-name.

Switch to @bitdancer's fix from review feedback. Recharacterize space
between ews as fws after parsing in get_phrase.

RDM: This fix is dependent on the fact that "subsequent" atoms will never have
leading whitespace because that's been consumed already. I don't think
it's worth adding extra code for the possibility of leading whitespace
because the parser won't produce it. It's a bit of parser fragility in the
face of code changes, but I think that's a minor concern given the
parser design (which is that it consumes whitespace greedily)
(cherry picked from commit 7a4c6dfb88)

Co-authored-by: Mike Edmunds <medmunds@gmail.com>
Co-authored-by: R David Murray <rdmurray@bitdance.com>
2026-05-13 16:29:07 -04:00
Miss Islington (bot)
bb3446dda6
[3.13] gh-87451: Apply CVE-2021-4189 PASV fix to ftplib.ftpcp() (GH-149648) (#149794)
gh-87451: Apply CVE-2021-4189 PASV fix to ftplib.ftpcp() (GH-149648)

ftpcp() called parse227() directly and passed the source server's
self-reported PASV IPv4 address to the target server's PORT command,
bypassing the CVE-2021-4189 fix that was applied only to FTP.makepasv().
A malicious source FTP server could use this to redirect the target
server's data connection to an arbitrary host:port (SSRF).

ftpcp() now uses the source server's actual peer address, honoring the
existing trust_server_pasv_ipv4_address opt-out, the same as makepasv().

Thanks to Qi Ding at Aurascape AI for the report. (GHSA-w8c5-q2xf-gf7c)
(cherry picked from commit eac4fe3b2c)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
2026-05-13 17:58:26 +00:00
Miss Islington (bot)
49d08674d8
[3.13] gh-149776: Skip UDP Lite tests if it's not supported (GH-149777) (#149782)
gh-149776: Skip UDP Lite tests if it's not supported (GH-149777)

Fix test_socket on Linux kernel 7.1 and newer: skip UDP Lite tests if
it's not supported.
(cherry picked from commit 3cfc249e11)

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-05-13 15:27:56 +00:00
Miss Islington (bot)
4e2cf29607
[3.13] gh-148821: Add more strict tests for XML encodings (GH-149765) (GH-149772)
Exclude encodings like 'utf-8-sig', 'iso2022-jp' and 'hz' from the list of
supported encodings.
(cherry picked from commit fa2afa64d9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-05-13 11:05:06 +00:00
Miss Islington (bot)
9e220bbfeb
[3.13] gh-149701: Fully silence potential hash -r error (GH-149702) (GH-149759)
(cherry picked from commit cd6096887e)
2026-05-13 09:22:02 +01:00
Miss Islington (bot)
d36f61d8c8
[3.13] Update mypy to 2.1.0 (GH-149709) (#149713)
Update mypy to 2.1.0 (GH-149709)
(cherry picked from commit b546cc10f5)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-05-12 09:06:58 +00:00
Miss Islington (bot)
5ad22a8de6
[3.13] gh-112821: Fix rlcompleter failures on objects with descriptors (GH-149577) (#149658)
* gh-112821: Fix rlcompleter failures on objects with descriptors (GH-149577)

* gh-112821: Fix rlcompleter failures on objects with descriptors

* Confirm no accesses
(cherry picked from commit f23a1837d7)

Co-authored-by: Michael Droettboom <mdboom@gmail.com>

* Add missing import

---------

Co-authored-by: Michael Droettboom <mdboom@gmail.com>
Co-authored-by: Michael Droettboom <mdroettboom@nvidia.com>
2026-05-11 12:08:20 -04:00
Miss Islington (bot)
0478bd83d8
[3.13] gh-149486: tarfile.data_filter: validate written link target (GH-149487) (GH-149555)
* gh-149486: tarfile.data_filter: validate written link target (GH-149487)

The data filter rewrote linknames with normpath() but ran the
containment check against the un-normalised value, and computed a
symlink's directory before stripping trailing slashes.  Both let a
crafted archive create links pointing outside the destination.  Also
reject link members that resolve to the destination directory itself,
which could otherwise replace it with a symlink and redirect all
subsequent members.

(Patch by Greg; Petr's just reviewing & merging.)
(cherry picked from commit 578411982c)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2026-05-11 11:58:26 +02:00
Miss Islington (bot)
6ab65b3e7e
[3.13] gh-149388: Make asyncio PipeHandle.close idempotent (GH-149518) (#149607)
gh-149388: Make asyncio `PipeHandle.close` idempotent (GH-149518)
(cherry picked from commit 7241f2739c)

Co-authored-by: Max Schmitt <max@schmitt.mx>
2026-05-09 20:38:09 +05:30
Miss Islington (bot)
ba894f1767
[3.13] gh-79638: Test other HTTP error codes besides 403 in test_robotparser (GH-149569) (GH-149582)
Also, use urllib.request.urlcleanup() in NetworkTestCase.
(cherry picked from commit 57ef219950)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-05-08 20:46:14 +00:00
Miss Islington (bot)
05956df2c2
[3.13] gh-148390: fix undefined behavior of memoryview(...).cast("?") (GH-148454) (GH-149299)
(cherry picked from commit 69e0a78e6e)
(cherry picked from commit 454401c8e9)

Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-05-08 17:50:00 +02:00
Miss Islington (bot)
99c9b85ad8
[3.13] gh-149410: Test that typing.NoDefault is final (GH-149411) (#149420)
gh-149410: Test that `typing.NoDefault` is final (GH-149411)
(cherry picked from commit bad9296fb0)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-05-05 15:22:48 +00:00
Miss Islington (bot)
67c47ce163
[3.13] gh-149403: Fix NameError in Lib/test/test_capi/test_getargs.py (GH-149404) (#149407)
gh-149403: Fix `NameError` in `Lib/test/test_capi/test_getargs.py` (GH-149404)
(cherry picked from commit 114781040c)

Co-authored-by: sobolevn <mail@sobolevn.me>
2026-05-05 14:47:46 +03:00
Savannah Ostrowski
a02beabe2d
[3.13] GH-130750: Restore quoting of choices in argparse error messag… (#149386)
[3.13] GH-130750: Restore quoting of choices in argparse error messages to match documentation and improve clarity (GH-144983)
(cherry picked from commit 53a7f76501)
2026-05-04 23:18:05 +00:00
Serhiy Storchaka
561d1b95b9
[3.13] gh-138907: Support RFC 9309 in robotparser (GH-138908) (GH-149376)
* empty lines are always ignored instead of separating groups
* the "user-agent" line after a rule starts a new group
* groups matching the same user agent are now merged
* the rule with the longest match wins instead of the first matching rule
* in case of equal matches, the “Allow” rule wins over “Disallow”
* special characters “$” and “*” are now supported in rules
* prefer full match for user agent

(cherry picked from commit bc285e5832)
2026-05-04 18:43:03 +00:00
Miss Islington (bot)
023ecbd01f
[3.13] gh-148093: Raise binascii.Error from binascii.a2b_uu() on empty input (GH-149077) (GH-149349)
Instead of reading past the end of the empty buffer.
(cherry picked from commit 0c6d2f64c0)

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
2026-05-04 10:06:25 +00:00
Miss Islington (bot)
6a2f12b031
[3.13] gh-148663: Document that calendar.IllegalMonthError inherits from both ValueError and IndexError (GH-148664) (#148918)
(cherry picked from commit 435be06dd2)

Co-authored-by: Eoin Shaughnessy <45000144+EoinTrial@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-05-03 17:42:39 +01:00
Miss Islington (bot)
302ef2122c
[3.13] gh-148914: Fix memoization of in-band PickleBuffer in the Python implementation (GH-149052) (GH-149275)
Previously, identical PickleBuffers did not preserve identity.
Also, empty writable PickleBuffer memoized an empty bytearray object
in place of b'' which is a singleton in CPython, so the following
references to b'' were unpickled as an empty bytearray object.
(cherry picked from commit b89735625d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-05-02 11:11:15 +00:00
Miss Islington (bot)
bb2c05b398
[3.13] gh-149117: Set ImportError.name on errors from runpy.run_module/run_path (gh-149159) (#149258)
gh-149117: Set `ImportError.name` on errors from `runpy.run_module`/`run_path` (gh-149159)

Set ImportError.name on errors from runpy.run_module/run_path

`runpy.run_module()` and `runpy.run_path()` now set the `name` attribute
of the `ImportError` they raise to the requested module name, matching
the behaviour of a regular import statement (previously `name` was
always `None`, which broke introspection).

The `name=` kwarg is gated on `issubclass(error, ImportError)` because
`_get_module_details()` is also used by `_run_module_as_main()` with
a private `_Error` sentinel class. `_Error` does not subclass
ImportError, and `BaseException.__init__` rejects unknown kwargs at
the C level, so passing `name=` unconditionally would break the
`python -m foo` codepath.
(cherry picked from commit ff35fe4633)

Co-authored-by: W. H. Wang <mattwang44@gmail.com>
2026-05-02 02:51:06 +00:00
Miss Islington (bot)
104a38c495
[3.13] gh-148518 fix index error in local part attribute (GH-148522) (#149199)
As part of fixing bpo-27931 code was introduced to get_bare_quoted_string
that added an empty Terminal if the quoted string was empty.  This isn't
the best answer in terms of the parse tree; we really want the token
list to be empty in that case.  But having it be empty resulted in
local_part raising the index error.  We find that same problem if we
try to parse an address consisting of a single dquote.  By fixing
local_part to not raise on an empty token list, we can have the
bare_quoted_string code correctly return an empty token list for
the empty string cases (two dquotes or a single dquote as the
entire addrespec, at the end of a line).
(cherry picked from commit bdbb55c403)

Co-authored-by: R. David Murray <rdmurray@bitdance.com>
2026-04-30 18:13:27 -04:00
Miss Islington (bot)
b3e0c72fa4
[3.13] bpo-39100: _header_value_parser: do not treat a Group as invalid-mailbox (GH-24872) (#149192)
When an address in an address-list has garbage at the end, the code will
currently:

1. change the mailbox in the last parsed address into invalid-mailbox by
   overriding its token_type;
2. wrap the trailing garbage into another invalid-mailbox and append it
   to the last parsed address.

However, that does not take into account that an address may
also contain a Group instead of a single mailbox. In that case,
overwriting token_type leads to undesirable results, e.g. parsing an
email with the following 'To' header:

unlisted-recipients:; (no To-header on input)

raises an AttributeError from trying to treat the Group as a Mailbox.

Moreover it is questionable whether the previously parsed mailbox should
be treated as invalid in addition to the trailing garbage.

Address both of the above by wrapping the trailing garbage in a new
Address with a single invalid-mailbox, and append it to the AddressList
directly.

Changes the results of the
test_get_address_list_mailboxes_invalid_addresses test, where the
address list is now parsed into 4 mailboxes instead of 3 (all but the
first one are invalid).
(cherry picked from commit b413bc7a1f)

Co-authored-by: elenril <anton@khirnov.net>
2026-04-30 14:15:43 -04:00
Miss Islington (bot)
d6d68494be
[3.13] gh-148169: Fix webbrowser %action substitution bypass of dash-prefix check (GH-148170) (#148517)
Co-authored-by: Stan Ulbrych <stan@python.org>
2026-04-29 13:00:10 +03:00
Miss Islington (bot)
0c83e503cd
[3.13] gh-140287: Handle PYTHONSTARTUP script exceptions in the asyncio REPL (GH-140288) (#148988)
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2026-04-29 12:57:19 +03:00
Miss Islington (bot)
ab5ef98af6
[3.13] gh-146581: Fix vulnerability in shutil.unpack_archive() for ZIP files on Windows (GH-146591) (GH-149065)
Use ZipFile.extractall() to sanitize file names and extract files.

Files with invalid names (e.g. absolute paths) are now skipped.

Files containing ".." in the name are no longer skipped.
(cherry picked from commit fc829e8875)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-04-27 22:54:45 +03:00
Gregory P. Smith
9651429aa7
[3.13] gh-105936: Properly update closure cells for __setattr__ and __delattr__ in frozen dataclasses with slots (GH-144021) (GH-148476)
gh-105936: Properly update closure cells for `__setattr__` and `__delattr__` in frozen dataclasses with slots (GH-144021)
(cherry picked from commit 8a398bfbbc)

The cherry-pick required additional changes beyond the original commit
because 3.13 lacks the `__class__` closure cell fixup machinery that
was added in 3.14 by GH-124455 (gh-90562). Specifically:

- Backported `_update_func_cell_for__class__()` helper function and the
  closure fixup loop in `_add_slots()` from GH-124455. Without these,
  renaming the closure variable from `cls` to `__class__` has no effect
  because nothing updates the cell when the class is recreated with slots.
- Changed `_add_slots()` to use `newcls` instead of reusing `cls` for the
  recreated class, so both old and new class references are available for
  the fixup loop.
- Replaced `assertNotHasAttr` with `assertFalse(hasattr(...))` in tests
  (assertNotHasAttr was added in 3.14).
- Dropped `test_original_class_is_gced` additions (that test does not
  exist on 3.13; it was added by GH-137047 for gh-135228 which was not
  backported to 3.13).

gh-148947: dataclasses: fix error on empty __class__ cell  (GH-148948)

Also add a test demonstrating the need for the existing "is oldcls" check.
(cherry picked from commit 6d7bbee1d5)

---------

Co-authored-by: Prometheus3375 <prometheus3375@gmail.com>
Co-authored-by: Sviataslau <35541026+Prometheus3375@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2026-04-25 22:55:20 -07:00
Miss Islington (bot)
898ecdd2e9
[3.13] gh-141473: Speed up subprocess test_communicate_timeout_large_input long tail (GH-149003) (#149005)
gh-141473: Speed up subprocess test_communicate_timeout_large_input long tail (GH-149003)

gh-141473: Speed up test_communicate_timeout_large_input

Replace the slow reader's 30s sleep with a parent-driven wake over a
loopback socket so post-timeout communicate() doesn't block waiting
for the child to wake on its own. Worst-case runtime: ~30s -> <1s.
(cherry picked from commit e1384cfd25)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
2026-04-26 04:27:03 +00:00
Irit Katriel
8da3d39c51
[3.13] gh-148973: fix segfault on mismatch between consts size and oparg in compiler (GH-148974) (#148997) 2026-04-25 22:59:40 +01:00
Stan Ulbrych
feafd5f69c
[3.13] gh-148735: Fix a UAF in Element.findtext() (GH-148738) (#148923)
(cherry picked from commit 0469e6d38d)
2026-04-25 10:38:14 +01:00
Miss Islington (bot)
e4ae72a6d9
[3.13] gh-132631: Fix "I/O operation on closed file" when parsing JSON Lines file (GH-132632) (#148922)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
2026-04-23 19:30:13 +00:00
Miss Islington (bot)
3c59b8b53f
[3.13] gh-90309: Base64-encode cookie values embedded in JS (GH-148888)
(cherry picked from commit 76b3923d68)

Co-authored-by: Seth Larson <seth@python.org>
2026-04-23 15:05:17 +02:00
Miss Islington (bot)
f540bc9d4a
[3.13] gh-146553: Fix infinite loop in typing.get_type_hints() on circular __wrapped__ (GH-148595) (#148896)
(cherry picked from commit be833e658a)

Co-authored-by: Shamil <ashm.tech@proton.me>
2026-04-23 02:55:40 +00:00
Miss Islington (bot)
95633d2aad
[3.13] gh-148808: Add boundary check to asyncio.AbstractEventLoop.sock_recvf… (GH-148809) (#148836)
gh-148808: Add boundary check to asyncio.AbstractEventLoop.sock_recvf… (GH-148809)
(cherry picked from commit 1274766d3c)

Co-authored-by: Seth Larson <seth@python.org>
2026-04-21 21:56:37 +05:30
Miss Islington (bot)
a60194609a
[3.13] gh-148653: Fix reference leaks in test_marshal introduced in gh-148698 (GH-148725) (GH-148728)
(cherry picked from commit 7ce737ea11)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-04-18 12:34:25 +00:00
Serhiy Storchaka
ac1c1e7ef0
[3.13] gh-148653: Fix some marshal errors related to recursive code objects (GH-148698) (GH-148711) (GH-148713)
(cherry picked from commit d496c637a3)

Forbid marshalling recursive code objects which
cannot be correctly unmarshalled.
Add multiple tests for recursive data structures.
(cherry picked from commit 2e37d83641)
2026-04-18 09:29:38 +00:00
Petr Viktorin
a5969e8f0f
[3.13] gh-146333: Fix quadratic regex backtracking in configparser option parsing (GH-146399) (GH-148559)
Use negative lookahead in option regex to prevent backtracking, and to avoid changing logic outside the regexes (since people could use the regex directly).
(cherry picked from commit 7e0a0be409)

Co-authored-by: Joshua Swanson <22283299+joshuaswanson@users.noreply.github.com>
2026-04-15 12:11:10 +02:00
Miss Islington (bot)
5a4143a392
[3.13] gh-148192: Fix Generator._make_boundary behavior with CRLF line endings. (GH-148193) (#148549)
The Generator._make_boundary regex did not match on boundary phrases correctly when using CRLF line endings due to re.MULTILINE not considering \r\n as a line ending.
(cherry picked from commit 4af46b4ab5)

Co-authored-by: Henry Jones <44321887+henryivesjones@users.noreply.github.com>
2026-04-14 12:21:55 -04:00
Victor Stinner
63c9aa60a6
[3.13] gh-148487: Fix issues in test_add_python_opts (#148507) (#148546)
gh-148487: Fix issues in `test_add_python_opts` (#148507)

(cherry picked from commit 44f1b987ed)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-04-14 10:08:32 +00:00
Miss Islington (bot)
ff88ee4b3a
[3.13] gh-148508: Add resilience to SSL preauth tests on iOS (GH-148536) (#148540)
Adds handling for a test case seen in the iOS SSL tests where an SSL connection fails to
handshake correctly.
(cherry picked from commit c40e8b016a)

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
2026-04-14 11:54:43 +08:00
Miss Islington (bot)
a69b14bc01
[3.13] gh-148370: prevent quadratic behavior in configparser.ParsingError.combine (GH-148452) (#148533)
gh-148370: prevent quadratic behavior in `configparser.ParsingError.combine` (GH-148452)
(cherry picked from commit 2662db0c45)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-04-13 23:05:38 +00:00
Miss Islington (bot)
74be9e2c76
[3.13] tests: use errno.EBADF instead of hardcoded number in _close_file() (GH-148345) (#148411)
tests: use errno.EBADF instead of hardcoded number in _close_file() (GH-148345)

test_interpreters: use errno.EBADF instead of hardcoded number in _close_file()

Replace the hardcoded `9` check in `Lib/test/test_interpreters/utils.py` with `errno.EBADF`.

Using `errno.EBADF` makes the helper portable across platforms with different errno numbering while preserving the intended behavior.
(cherry picked from commit cef334fd4c)

Co-authored-by: Artem Yarulin <artem.yarulin@kapteko.com>
2026-04-12 18:13:53 -07:00
Miss Islington (bot)
a268d3fcef
[3.13] gh-146313: Fix multiprocessing ResourceTracker deadlock after os.fork() (GH-146316) (#148426)
gh-146313: Fix multiprocessing ResourceTracker deadlock after os.fork() (GH-146316)

`ResourceTracker.__del__` (added in gh-88887 circa Python 3.12) calls
os.waitpid(pid, 0) which blocks indefinitely if a process created via os.fork()
still holds the tracker pipe's write end. The tracker never sees EOF, never
exits, and the parent hangs at interpreter shutdown.

Fix with two layers:

- **At-fork handler.** An os.register_at_fork(after_in_child=...)
  handler closes the inherited pipe fd in the child unless a preserve
  flag is set. popen_fork.Popen._launch() sets the flag before its
  fork so mp.Process(fork) children keep the fd and reuse the parent's
  tracker (preserving gh-80849). Raw os.fork() children close the fd,
  letting the parent reap promptly.

- **Timeout safety-net.** _stop_locked() gains a wait_timeout
  parameter. When called from `__del__`, it polls with WNOHANG using
  exponential backoff for up to 1 second instead of blocking
  indefinitely. The at-fork handler makes this unreachable in
  well-behaved paths; it remains for abnormal shutdowns.
(cherry picked from commit 3a7df632c9)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Itamar Oren <itamarost@gmail.com>
2026-04-12 10:08:36 -07:00
Miss Islington (bot)
8e369d3645
[3.13] gh-145105: Fix crash in csv.reader with re-entrant iterator (GH-145106) (#148405)
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.
(cherry picked from commit 20994b1809)

Co-authored-by: Ramin Farajpour Cami <ramin.blackhat@gmail.com>
2026-04-11 22:44:45 +00:00