gh-87720 Fix additional header refolding-quoting edge case (GH-134271)
In this case, the higher level syntactic unit fit on the remainder of
the line in un-encoded format, and that higher level unit was
not a ptext or vtext, so the encoding check failed. To fix this, we
look inside the current unit to see if has anything that was
originally encoded.
(cherry picked from commit 5a22a62b96)
Co-authored-by: R. David Murray <rdmurray@bitdance.com>
Co-authored-by: T. Wouters <thomas@python.org>
gh-160097: Reject links replacing the destination in `tarfile.tar_filter` (GH-160098)
(cherry picked from commit e7e0b3523a)
Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: T. Wouters <thomas@python.org>
* gh-157579: Fix race condition in the cleanup of `tempfile.TemporaryDirectory` (GH-157580)
(cherry picked from commit 5c20517a4f)
Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
* Add root user checks to test.support
This partially backports commit 86b8617747
(GH-146195); making existing tests use the helper is omitted.
* Skip test on Android
* Skip other affected test
---------
Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: T. Wouters <thomas@python.org>
gh-160300: Reject cookies with a negative version in http.cookiejar (GH-160301)
DefaultCookiePolicy only applied its domain checks to cookies with
version 0 or a positive version.
ANT-2026-TA36I7V7
(cherry picked from commit d59d96853b)
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Docs: Fix installer name in the macOS command-line install example (GH-160527)
(cherry picked from commit 5ca490bda6)
Co-authored-by: Davi de Jesus <davidejesus.log@proton.me>
Make knownfiles empty on Windows so that only the registry is used by default. Files passed to init() or assigned to knownfiles explicitly are still read.
(cherry picked from commit 04a29bf8f9)
The 3.13 backport of gh-152563 compares the return value of
support.linked_to_musl() with a version tuple, but on 3.13 the helper
still returns a bool. On musl this raises TypeError at class definition
time, so test_math and test_cmath fail to import. Restore the previous
skip condition.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
gh-159914: Ignore gdb stderr in test_gdb.test_pretty_print (GH-159916)
test_strings() gets gdb.host_charset(), but fails if gdb writes
anything to stderr. For example, it fails if gdb logs the warning:
"/usr/bin/gdb: warning: Couldn't determine a path for the index
cache directory."
Even if stdout contains the expected encoding ("UTF-8").
Change test_gdb to only fail if stdout is empty, ignore stderr
otherwise to ignore gdb warnings.
(cherry picked from commit 88d922ad98)
Co-authored-by: Victor Stinner <vstinner@python.org>
The ssl module now rejects TLS certificate chains that contain any of a set of
compromised eMudhra intermediate CA keys. This is an extraordinary measure and
a last line of defense: removing trust is primarily the job of the platform root
store, and the built-in denylist only blocks connections while that update has
not yet reached the OS, a container image, or a bundled trust store in various
Python packages. Entries are added to the denylist only under a very high
threshold.
The denylist matches on the public key (the SHA-256 digest of the RFC-5280
SubjectPublicKeyInfo), so it also covers the cross-signed certificates that
reuse one of the distrusted keys.
(cherry picked from commit 7dd8b4736a)
Co-authored-by: Christian Heimes <christian@python.org>
[3.14] Add Sphinx markup for CVEs in Changelog entries (GH-159415) (GH-159913)
(cherry picked from commit aa5b0ed2b4)
(cherry picked from commit 44a2c1a5d9)
Co-authored-by: Stan Ulbrych <stan@python.org>
Add os.supports_dir_fd to test.pythoninfo (GH-158605)
Split the attribute lists so the 'supports_*' names don't need
to be repeated twice.
Add 'supports_dir_fd'.
(cherry picked from commit eb77b4b2e4)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
gh-158446: Reject float format precision near INT_MAX (GH-158474)
Formatting a float or complex with a precision within about 1000 of
INT_MAX could crash or produce incorrect output.
PyOS_double_to_string() now raises ValueError("precision too big") for
such precisions, as the format string parsers already do for
precisions above INT_MAX.
The limit applies regardless of presentation type or value, so a few
calls that previously succeeded (inf, nan, or 'g' with such a
precision) now raise as well.
(cherry picked from commit b7b4f3ecf2)
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
When a replacement field ended with a string that had an escaped quote and
was followed by a comment, the comment leaked into the debug f-string output.
The comment detection loop in set_fstring_expr skips escaped characters, but
the comment stripping loop did not. So an escaped quote left the scanner
thinking it was still inside a string, and the comment was never removed.
This makes the stripping loop skip escaped characters the same way the
detection loop does. 3.14 and later already have this fix from gh-154719.
_Py_hashtable_set() returns -1 on failure, so the "< -1" check could never be true and the Py_FatalError() call was unreachable.
(cherry picked from commit a4eb936727)
Co-authored-by: Rishi Raj <180109771+rishiraj38@users.noreply.github.com>
A test which really allocates the memory it asks for (that is, run with -M)
now runs in a subprocess, so that the memory it uses and the address space
it fragments are released when it ends. A dummy run stays in the process.
The separate watchdog process is no longer used. Unlike in the main branch,
the parent process does not report the memory usage of the subprocess:
get_process_memory_usage() (gh-150114) is not available on this branch.
(cherry picked from commit 66d7c89104)
* [3.15] gh-156002: Bound zipfile decompression for bzip2/LZMA/Zstandard (GH-156003) (GH-156362)
Patch by @tonghuaroot.
zipfile.ZipExtFile._read1() bounds the output of each decompress() call
for DEFLATE members by passing a max_length to zlib, but for bzip2, LZMA,
and Zstandard members it called decompress() with no bound. A whole
compressed chunk was therefore expanded into a single allocation before
the data[:self._left] clip ran, so a consumer that deliberately reads in
small chunks to limit memory (for example zf.open(name).read(8192)) was
silently unprotected for non-DEFLATE members. A small, spec-conformant
archive member declaring a large uncompressed size could drive multi-GB
peak memory.
_read1() now passes a per-call bound to the non-DEFLATE decompress()
(mirroring the DEFLATE branch) and drains the decompressor's internal
buffer across calls by checking needs_input before reading more
compressed input. zipfile's LZMADecompressor wrapper forwards max_length
and exposes needs_input so the bound also holds for LZMA members.
(cherry picked from commit f897dbf2f3)
(cherry picked from commit 1b424c0178)
* gh-156002: Keep reading through monkey-patched zipfile decompressors (GH-157180) (GH-157557)
(cherry picked from commit f507e6946a)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: tonghuaroot <tonghuaroot@gmail.com>
Co-authored-by: rasmusfaber <rfaber@gmail.com>
gh-156920, gh-156698: fix ProactorEventLoop datagram transport hangs on close() and after write errors (GH-156921)
(cherry picked from commit 7f52444d9b)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
gh-154175: Fetch _PY_GIL_DROP_REQUEST_BIT under GIL
Once the GIL is released the tstate may be freed which shows up as ASAN
and TSAN failures in test_io with daemon threads. Check the bit before
dropping the GIL so the tstate is guaranteed to still be allocated.
Remove the TSAN suppressions which were added for 3.13 as this should
fix this case.
CalledProcessError.__str__() fell through to a branch that formats the
return code with %d, which raises TypeError when returncode is None.
(cherry picked from commit 7c653e2540)
Co-authored-by: Vyron Vasileiadis <hi@fedonman.com>
gh-82535: Ignore address resolution failure in SysLogHandler constructor (GH-154504)
The address may be temporarily unresolvable when the handler is created.
It is resolved again when a record is emitted.
(cherry picked from commit c294654287)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Test PySlice_Check(), PySlice_New(), PySlice_GetIndices(), PySlice_Unpack(),
PySlice_AdjustIndices() and PySlice_GetIndicesEx() -- both the macro and the
deprecated function.
Document the length and step precondition of PySlice_AdjustIndices()
(cherry picked from commit 8c056c33aa)
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Victor Stinner <vstinner@python.org>