Commit graph

29453 commits

Author SHA1 Message Date
Serhiy Storchaka
0c33e5baed [3.11] gh-133767: Fix use-after-free in the unicode-escape decoder with an error handler (GH-129648) (GH-133944)
If the error handler is used, a new bytes object is created to set as
the object attribute of UnicodeDecodeError, and that bytes object then
replaces the original data. A pointer to the decoded data will became invalid
after destroying that temporary bytes object. So we need other way to return
the first invalid escape from _PyUnicode_DecodeUnicodeEscapeInternal().

_PyBytes_DecodeEscape() does not have such issue, because it does not
use the error handlers registry, but it should be changed for compatibility
with _PyUnicode_DecodeUnicodeEscapeInternal().
(cherry picked from commit 9f69a58623)
(cherry picked from commit 6279eb8c07)
(cherry picked from commit a75953b347)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-05-20 18:12:29 +03:00
Miss Islington (bot)
461ca2cbfb
[3.11] gh-126500: test_ssl: Don't stop ThreadedEchoServer on OSError in ConnectionHandler; rely on __exit__ (GH-126503) (GH-126572) (GH-133148)
gh-126500: test_ssl: Don't stop ThreadedEchoServer on OSError in ConnectionHandler; rely on __exit__ (GH-126503)

If `read()` in the ConnectionHandler thread raises `OSError` (except `ConnectionError`),
the ConnectionHandler shuts down the entire ThreadedEchoServer,
preventing further connections.
It also does that for `EPROTOTYPE` in `wrap_conn`.

As far as I can see, this is done to avoid the server thread getting stuck,
forgotten, in its accept loop. However, since 2011 (5b95eb90a7)
the server is used as a context manager, and its `__exit__` does `stop()` and `join()`.
(I'm not sure if we *always* used `with` since that commit, but currently we do.)

Make sure that the context manager *is* used, and remove the `server.stop()`
calls from ConnectionHandler.

(cherry picked from commit c9cda1608e)
(cherry picked from commit aee80cd5e7)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-05-14 20:31:04 +02:00
Miss Islington (bot)
0a66052d8d
[3.11] gh-121284: Fix email address header folding with parsed encoded-word (GH-122754) (GH-131405)
Email generators using email.policy.default may convert an RFC 2047
encoded-word to unencoded form during header refolding. In a structured
header, this could allow 'specials' chars outside a quoted-string,
leading to invalid address headers and enabling spoofing. This change
ensures a parsed encoded-word that contains specials is kept as an
encoded-word while the header is refolded.

[Better fix from @bitdancer.]

(cherry picked from commit 295b53df2a)

Co-authored-by: Mike Edmunds <medmunds@gmail.com>
Co-authored-by: R David Murray <rdmurray@bitdance.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-04-03 18:27:02 +02:00
Diego Russo
f576d31d1c
[3.11] gh-106883: Make test_current_frames_exceptions_deadlock faster (#131182) 2025-03-14 01:59:59 +00:00
Diego Russo
6b37486184
[3.11] gh-106883 Fix deadlock in threaded application (#117332)
When using threaded applications, there is a high risk of a deadlock in
the interpreter. It's a lock ordering deadlock with HEAD_LOCK(&_PyRuntime); and the GIL.

By disabling the GC during the _PyThread_CurrentFrames() and
_PyThread_CurrentExceptions() calls fixes the issue.
2025-03-11 15:31:03 +00:00
Miss Islington (bot)
f1897d312e
[3.11] GH-130396: Treat clang -Og as optimized for gdb tests (GH-130550) (GH-130573) (#130593) 2025-02-27 12:43:48 +00:00
Miss Islington (bot)
3abcace681
[3.11] gh-119511: Fix a potential denial of service in imaplib (GH-119514) (#129357)
The IMAP4 client could consume an arbitrary amount of memory when trying
to connect to a malicious server, because it read a "literal" data with a
single read(size) call, and BufferedReader.read() allocates the bytes
object of the specified size before reading. Now the IMAP4 client reads data
by chunks, therefore the amount of used memory is limited by the
amount of the data actually been sent by the server.
(cherry picked from commit 735f25c5e3)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2025-02-19 14:16:30 +01:00
Miss Islington (bot)
526617ed68
[3.11] gh-105704: Disallow square brackets ([ and ]) in domain names for parsed URLs (GH-129418) (#129528)
Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2025-02-19 14:13:52 +01:00
Miss Islington (bot)
7cff053efe
[3.11] gh-80222: Fix email address header folding with long quoted-string (GH-122753) (#129009)
Email generators using email.policy.default could incorrectly omit the
quote ('"') characters from a quoted-string during header refolding,
leading to invalid address headers and enabling header spoofing. This
change restores the quote characters on a bare-quoted-string as the
header is refolded, and escapes backslash and quote chars in the string.
(cherry picked from commit 5aaf416858)

Co-authored-by: Mike Edmunds <medmunds@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-02-19 14:12:34 +01:00
Miss Islington (bot)
552ec42331
[3.11] gh-119461: Restore the testSocket VSOCK skipUnless removed by PR GH-119465 (GH-129561) (#129566)
gh-119461: Restore the testSocket VSOCK skipUnless removed by PR GH-119465 (GH-129561)

Restore the skipUnless removed by GH-119465.

This test can only pass on virtual machines, not actual machines.

actual machines see:

```
    self.cli.connect((cid, VSOCKPORT))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
OSError: [Errno 19] No such device
```

Reproduced on (Linux) Ubuntu 24.04.1 running 6.8.0-52-generic.
(cherry picked from commit e1006ce1de)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2025-02-13 01:32:37 +00:00
Victor Stinner
45db419c31
[3.11] gh-119461: Fix ThreadedVSOCKSocketStreamTest (#129171)
Fix ThreadedVSOCKSocketStreamTest: if get_cid() returns the host
address or the "any" address, use the local communication address
(loopback): VMADDR_CID_LOCAL.

On Linux 6.9, apparently, the /dev/vsock device is now available but
get_cid() returns VMADDR_CID_ANY (-1).

(cherry picked from commit e94dbe4ed8)
(cherry picked from commit c750061047)
(cherry picked from commit cbfe3023e4)
2025-01-23 22:14:08 +01:00
Miss Islington (bot)
66a01b068b
[3.11] gh-122792: Make IPv4-mapped IPv6 address properties consistent with IPv4 (GH-122793) (GH-123818)
Make IPv4-mapped IPv6 address properties consistent with IPv4.
(cherry picked from commit 76a1c5d183)

Co-authored-by: Seth Michael Larson <seth@python.org>

---------

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-12-03 17:57:10 +01:00
Petr Viktorin
8c6885d636
[3.11] gh-87846: test_io: Ignore OpenWrapper in test___all__ (#126478) 2024-11-06 13:39:30 +00:00
Victor Stinner
ae961ae94b
[3.11] gh-124651: Quote template strings in venv activation scripts (GH-124712) (GH-126185) (#126269) 2024-11-01 13:11:47 +00:00
Petr Viktorin
8630002c5c
[3.11] gh-125041: test_zlib: For s390x HW acceleration, only skip checking the compressed bytes (GH-125042) (#125577)
gh-125041: test_zlib: For s390x HW acceleration, only skip checking the compressed bytes (#125042)

(cherry picked from commit cc5a225cdc)
2024-10-22 12:11:14 +01:00
Petr Viktorin
bc4a703a93
[3.11] [CVE-2023-27043] gh-102988: Reject malformed addresses in email.parseaddr() (GH-111116) (#123767)
Detect email address parsing errors and return empty tuple to
indicate the parsing error (old API). Add an optional 'strict'
parameter to getaddresses() and parseaddr() functions. Patch by
Thomas Dwyer.

(cherry picked from commit 4a153a1d3b)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Thomas Dwyer <github@tomd.tel>
2024-09-06 12:46:23 +02:00
Jason R. Coombs
fc0b8259e6
[3.11] gh-123270: Replaced SanitizedNames with a more surgical fix. (GH-123354) (#123425)
Applies changes from zipp 3.20.1 and jaraco/zippGH-124
(cherry picked from commit 2231286d78)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>

* Restore the slash-prefixed paths in the malformed_paths test.
2024-09-04 17:52:54 +02:00
Miss Islington (bot)
d4ac921a4b
[3.11] gh-123067: Fix quadratic complexity in parsing "-quoted cookie values with backslashes (GH-123075) (#123105)
This fixes CVE-2024-7592.
(cherry picked from commit 44e458357f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-09-04 17:50:00 +02:00
Serhiy Storchaka
d0e8c100e4
[3.11] gh-67693: Fix urlunparse() and urlunsplit() for URIs with path starting with multiple slashes and no authority (GH-113563) (#119025)
(cherry picked from commit e237b25a4f)
2024-09-04 17:42:58 +02:00
Łukasz Langa
f7c0f09e69
[3.11] gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233) (#122608)
Per RFC 2047:

> [...] these encoding schemes allow the
> encoding of arbitrary octet values, mail readers that implement this
> decoding should also ensure that display of the decoded data on the
> recipient's terminal will not cause unwanted side-effects

It seems that the "quoted-word" scheme is a valid way to include
a newline character in a header value, just like we already allow
undecodable bytes or control characters.
They do need to be properly quoted when serialized to text, though.

Verify that email headers are well-formed.

This should fail for custom fold() implementations that aren't careful
about newlines.

(cherry picked from commit 0976339818)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Bas Bloemsaat <bas@bloemsaat.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-09-04 17:37:28 +02:00
Seth Michael Larson
d449caf8a1
[3.11] gh-121285: Remove backtracking when parsing tarfile headers (GH-121286) (#123639)
* Remove backtracking when parsing tarfile headers
* Rewrite PAX header parsing to be stricter
* Optimize parsing of GNU extended sparse headers v0.0

(cherry picked from commit 34ddb64d08)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-09-03 15:07:13 +00:00
Jason R. Coombs
795f2597a4
[3.11] gh-122905: Sanitize names in zipfile.Path. (GH-122906) (#122925)
* gh-122905: Sanitize names in zipfile.Path. (#122906)

Ported from zipp 3.19.1; ref jaraco/zipp#119.

(cherry picked from commit 9cd0326310)

* [3.11] gh-122905: Sanitize names in zipfile.Path. (GH-122906)

Ported from zipp 3.19.1; ref jaraco/zippGH-119.
(cherry picked from commit 9cd0326310)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
2024-08-20 00:28:20 +01:00
Inada Naoki
8a978a75c2
[3.11] gh-119506: fix _io.TextIOWrapper.write() write during flush (#119507) (#120314)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
fix _io.TextIOWrapper.write() write during flush (#119507)
2024-08-09 17:04:36 +00:00
Miss Islington (bot)
c5655aa6ad
[3.11] gh-122133: Rework pure Python socketpair tests to avoid use of importlib.reload. (GH-122493) (GH-122506)
(cherry picked from commit f071f01b7b)

Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-08-02 15:09:45 +02:00
Miss Islington (bot)
5f90abaa78
[3.11] gh-122133: Authenticate socket connection for socket.socketpair() fallback (GH-122134) (#122426)
Authenticate socket connection for `socket.socketpair()` fallback when the platform does not have a native `socketpair` C API.  We authenticate in-process using `getsocketname` and `getpeername` (thanks to Nathaniel J Smith for that suggestion).

(cherry picked from commit 78df1043db)

Co-authored-by: Seth Michael Larson <seth@python.org>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-07-30 14:43:45 +02:00
Steve Dower
35c799d791
[3.11] gh-118486: Support mkdir(mode=0o700) on Windows (GH-118488) (GH-118739) 2024-05-24 02:13:18 +02:00
Serhiy Storchaka
4762b36540
[3.11] gh-118643: Fix AttributeError in the email module (GH-119099) (#119393)
Fix regression introduced in gh-100884: AttributeError when re-fold a long
address list.

Also fix more cases of incorrect encoding of the address separator in the
address list missed in gh-100884.
(cherry picked from commit 858b9e85fc)
2024-05-23 13:09:03 +01:00
Petr Viktorin
ba431579ef
[3.11] gh-113171: gh-65056: Fix "private" (non-global) IP address ranges (GH-113179) (GH-113186) (GH-118177) (#118227) 2024-04-25 13:45:48 +01:00
Grigoriev Semyon
3bc0d2b851
[3.11] gh-109120: Fix syntax error in handlinh of incorrect star expressions… (#117464)
gh-109120: Fix syntax error in handlinh of incorrect star expressions (#117444)

(cherry picked from commit c97d3af239)
2024-04-03 11:37:39 +01:00
Miss Islington (bot)
38bcbb22f9
[3.11] gh-115538: Use pathlib to compare prefixes in test_venv (GH-117076)
gh-115538: Use pathlib to compare prefixes in test_venv (GH-117076)
(cherry picked from commit 52f5b7f9e0)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2024-04-02 13:31:08 +00:00
Miss Islington (bot)
54ee038615
[3.11] [3.12] gh-117347: Fix test_clinic side effects (GH-117363) (GH-117365) (#117366)
[3.12] gh-117347: Fix test_clinic side effects (GH-117363) (GH-117365)

gh-117347: Fix test_clinic side effects (GH-117363)

Save/restore converters in ClinicWholeFileTest and
ClinicExternalTest.

(cherry picked from commit c80d13838d)

Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 35b6c4a4da)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-03-29 11:21:56 +00:00
Miss Islington (bot)
01ab43c08a
[3.11] gh-117110: Fix subclasses of typing.Any with custom constructors (GH-117111) (#117358)
gh-117110: Fix subclasses of typing.Any with custom constructors (GH-117111)
(cherry picked from commit 8eec7ed714)

Co-authored-by: 傅立业(Chris Fu) <17433201@qq.com>
2024-03-29 00:38:13 +00:00
Victor Stinner
8bbb12169f
[3.11] gh-114331: Skip decimal test_maxcontext_exact_arith on s390x (#117326) (#117331)
gh-114331: Skip decimal test_maxcontext_exact_arith on s390x (#117326)

Add test.support.skip_on_s390x decorator.

(cherry picked from commit 6702d2bf6e)
2024-03-28 17:53:43 +00:00
Miss Islington (bot)
c703b7b54f
[3.11] gh-117178: Recover lazy loading of self-referential modules (GH-117179) (#117320)
Co-authored-by: Chris Markiewicz <effigies@gmail.com>
2024-03-28 11:17:10 +00:00
Miss Islington (bot)
370a7f1e4a
[3.11] gh-104242: Enable test_is_char_device_true in pathlib test on all platform (GH-116983) (GH-117277) (GH-117280)
(cherry picked from commit 17a82a1d16)
(cherry picked from commit af1b0e9440)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2024-03-27 08:57:08 +00:00
Miss Islington (bot)
3d853a4ee4
[3.11] [3.12] gh-115538: Use isolate mode when running venv test_multiproces… (GH-117264) (#117265)
[3.12] gh-115538: Use isolate mode when running venv test_multiproces… (GH-117264)

[3.12] gh-115538: Use isolate mode when running venv test_multiprocessing_recursion() (GH-117116)
(cherry picked from commit 4ec347760f)

(cherry picked from commit ca0793980b)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-03-26 17:13:23 +00:00
Miss Islington (bot)
2d932361a8
[3.11] gh-66543: Fix mimetype.guess_type() (GH-117217) (GH-117257)
Fix parsing of the following corner cases:

* URLs with only a host name
* URLs containing a fragment
* URLs containing a query
* filenames with only a UNC sharepoint on Windows

(cherry picked from commit 9654daf793)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
2024-03-26 11:46:28 +00:00
Miss Islington (bot)
1112e01da1
[3.11] gh-83845: Add tests for operator module (GH-115883) (#117254)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
2024-03-26 09:50:40 +00:00
Miss Islington (bot)
04b26eeb14
[3.11] [3.12] gh-83434: Sync libregrtest and test_regrtest with the main branch (GH-117250) (#117251)
[3.12] gh-83434: Sync libregrtest and test_regrtest with the main branch (GH-117250)

* gh-115122: Add --bisect option to regrtest (GH-115123)

* test.bisect_cmd now exit with code 0 on success, and code 1 on
  failure. Before, it was the opposite.
* test.bisect_cmd now runs the test worker process with
  -X faulthandler.
* regrtest RunTests: Add create_python_cmd() and bisect_cmd()
  methods.

(cherry picked from commit 1e5719a663)

* gh-115720: Show number of leaks in huntrleaks progress reports (GH-115726)

Instead of showing a dot for each iteration, show:
- '.' for zero (on negative) leaks
- number of leaks for 1-9
- 'X' if there are more leaks

This allows more rapid iteration: when bisecting, I don't need
to wait for the final report to see if the test still leaks.

Also, show the full result if there are any non-zero entries.
This shows negative entries, for the unfortunate cases where
a reference is created and cleaned up in different runs.

Test *failure* is still determined by the existing heuristic.

(cherry picked from commit af5f9d682c)

* gh-83434: Disable XML in regrtest when -R option is used (GH-117232)

(cherry picked from commit d52bdfb19f)

---------

(cherry picked from commit 477ef9015c)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-03-26 08:18:10 +00:00
Miss Islington (bot)
2f8d3a17d9
[3.11] gh-117187: Fix XML tests for vanilla Expat <2.6.0 (GH-117203) (GH-117245)
gh-117187: Fix XML tests for vanilla Expat <2.6.0 (GH-117203)

This fixes XML unittest fallout from the https://github.com/python/cpython/issues/115398 security fix.  When configured using `--with-system-expat` on systems with older pre 2.6.0 versions of libexpat, our unittests were failing.

* sax|etree: Simplify Expat version guard where simplifiable

Idea by Matěj Cepl

* sax|etree: Fix reparse deferral tests for vanilla Expat <2.6.0

This *does not fix* the case of distros with an older version of libexpat with the 2.6.0 feature backported as a security fix.  (Ubuntu is a known example of this with its libexpat1 2.5.0-2ubunutu0.1 package)
(cherry picked from commit 9f74e86c78)

Co-authored-by: Sebastian Pipping <sebastian@pipping.org>
2024-03-26 02:08:28 +00:00
Serhiy Storchaka
6261322e26
[3.11] gh-91227: Ignore ERROR_PORT_UNREACHABLE in proactor recvfrom() (GH-32011) (GH-117210)
(cherry picked from commit f11d0d8be8)

Co-authored-by: Erik Soma <stillusingirc@gmail.com>
2024-03-25 10:34:25 +00:00
Serhiy Storchaka
0d82047645
[3.11] gh-117084: Fix ZIP file extraction for directory entry names with backslashes on Windows (GH-117129) (GH-117162) (GH-117165)
(cherry picked from commit f3fee231d3)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 567ab3bd15)
2024-03-22 19:24:27 +00:00
Miss Islington (bot)
8440125460
[3.11] gh-117127: glob tests: Reopen dir_fd to pick up directory changes (GH-117128) (GH-117149)
gh-117127: glob tests: Reopen dir_fd to pick up directory changes (GH-117128)
(cherry picked from commit 42ae924d27)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-03-22 10:21:53 +00:00
Miss Islington (bot)
0ec8561574
[3.11] gh-117061: Fix test_posix.test_sched_setaffinity() on RHEL9 (GH-117126) (#117138)
gh-117061: Fix test_posix.test_sched_setaffinity() on RHEL9 (GH-117126)

On RHEL9, sched_setaffinity(0, []) does not fail.
(cherry picked from commit 50f9b0b1e0)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-03-21 22:37:16 +00:00
jkriegshauser
23a1c9f422
[3.11] gh-116773: Fix overlapped memory corruption crash (GH-116774) (#117077)
Manual backport of gh-116774.
2024-03-20 13:10:32 -07:00
David Röthlisberger
b517fd5e16
[3.11] gh-116957: configparser: Do post-process values after DuplicateOptionError (GH-116958) (GH-117012)
If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.

(cherry picked from commit b1bc37597f)
2024-03-19 18:19:04 +01:00
Victor Stinner
c7b01e3c32
[3.11] gh-90872: Fix subprocess.Popen.wait() for negative timeout (#116989) (#117003)
gh-90872: Fix subprocess.Popen.wait() for negative timeout (#116989)

On Windows, subprocess.Popen.wait() no longer calls
WaitForSingleObject() with a negative timeout: pass 0 ms if the
timeout is negative.

(cherry picked from commit 27cf3ed00c)
2024-03-19 14:21:42 +00:00
Miss Islington (bot)
299b6d06e8
[3.11] gh-105866: fix dataclass with slots=True, weakref_slot=True (GH-105870) (GH-116979)
(cherry picked from commit a22d05f04c)

Co-authored-by: Aviel Boag <avboag@gmail.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Carl Meyer <carl@oddbird.net>
2024-03-19 11:57:45 +01:00
Miss Islington (bot)
3b4cd48d29
[3.11] gh-90535: Fix support of interval>1 in logging.TimedRotatingFileHandler (GH-116220) (GH-116893)
Fix support of interval values > 1 in logging.TimedRotatingFileHandler
for when='MIDNIGHT' and when='Wx'.
(cherry picked from commit 269051d20e)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-03-18 19:47:53 +02:00
Kushal Das
a93974d452
[3.11] gh-116831: Fixes tests for c extension in WASI for Python 3.11 (GH-116831) (#116933)
gh-116831: Fixes tests for c extension in WASI

We can skip the C extension based tests under WASI.
2024-03-18 07:03:01 +01:00