Commit graph

13634 commits

Author SHA1 Message Date
Serhiy Storchaka
8eb25faed7
[3.12] gh-67877: Fix memory leaks in terminated RE matching (GH-126840) (GH-126961)
If SRE(match) function terminates abruptly, either because of a signal
or because memory allocation fails, allocated SRE_REPEAT blocks might
be never released.

(cherry picked from commit 7538e7f569)
2024-11-18 11:24:13 +00:00
Miss Islington (bot)
9e86d211fc
[3.12] gh-126623: Update libexpat to 2.6.4, make future updates easier (GH-126792) (GH-126797)
gh-126623: Update libexpat to 2.6.4, make future updates easier (GH-126792)

Update libexpat to 2.6.4, make future updates easier.
(cherry picked from commit 3c99969094)

Co-authored-by: Seth Michael Larson <seth@python.org>
2024-11-13 18:50:29 +00:00
Bénédikt Tran
46710ca5f2
[3.12] gh-126595: fix a crash when calling itertools.count(sys.maxsize) (GH-126617) (#126740)
gh-126595: fix a crash when calling `itertools.count(sys.maxsize)` (#126617)
2024-11-12 14:05:23 +00:00
Miss Islington (bot)
b13b84ab70
[3.12] gh-126405: fix use-after-free in _asyncio.Future.remove_done_callback (GH-126733) (#126737)
gh-126405: fix use-after-free in `_asyncio.Future.remove_done_callback` (GH-126733)
(cherry picked from commit 37c57dfad1)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-11-12 13:04:25 +00:00
Miss Islington (bot)
97ab3cf374
[3.12] gh-126461: Fix _Unpickler_ReadFromFile() error handling (GH-126485) (#126496)
gh-126461: Fix _Unpickler_ReadFromFile() error handling (GH-126485)

Handle _Unpickler_SetStringInput() failure.
(cherry picked from commit a1c57bcfd2)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-11-06 13:49:25 +00:00
Miss Islington (bot)
e6fd40ba18
[3.12] gh-126455: Disallow _ssl.SSLSocket instantiation (GH-126481) (#126487)
gh-126455: Disallow _ssl.SSLSocket instantiation (GH-126481)

Prevent creation of incomplete/invalid _ssl.SSLSocket objects when
created directly.
(cherry picked from commit b1c4ffc205)

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-11-06 11:21:21 +00:00
Miss Islington (bot)
786886a926
[3.12] gh-126425: Refactor _lsprof_Profiler_enable (GH-126426) (#126443)
gh-126425: Refactor `_lsprof_Profiler_enable` (GH-126426)

- Explicit memory management for `None` objects (since we still try to treat immortal objects as regular objects)
- Respect possible errors of `sys.monitoring.register_callback` call
(cherry picked from commit 75872605aa)

Co-authored-by: sobolevn <mail@sobolevn.me>
2024-11-05 12:42:33 +00:00
Serhiy Storchaka
844d908adb
[3.12] gh-126303: Fix pickling and copying of os.sched_param objects (GH-126336) (GH-126424)
(cherry picked from commit d3840503b0)
2024-11-05 06:52:51 +00:00
Miss Islington (bot)
b59269961f
[3.12] gh-126138: Fix use-after-free in _asyncio.Task by evil __getattribute__ (GH-126305) (#126325)
gh-126138: Fix use-after-free in `_asyncio.Task` by evil `__getattribute__` (GH-126305)
(cherry picked from commit f032f6ba8f)

Co-authored-by: Nico-Posada <102486290+Nico-Posada@users.noreply.github.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2024-11-02 08:03:51 +00:00
Miss Islington (bot)
b5c19bdba8
[3.12] gh-126220: Fix crash on calls to _lsprof.Profiler methods with 0 args (backportable) (GH-126271) (#126311)
gh-126220: Fix crash on calls to `_lsprof.Profiler` methods with 0 args (backportable) (GH-126271)
(cherry picked from commit 28b148fb32)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-11-01 22:18:50 +00:00
Miss Islington (bot)
dc3c075d9e
[3.12] gh-126080: fix UAF on task->task_context in task_call_step_soon due to an evil loop.__getattribute__ (GH-126120) (#126251)
gh-126080: fix UAF on `task->task_context` in `task_call_step_soon` due to an evil `loop.__getattribute__` (GH-126120)
(cherry picked from commit 0e8665554b)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-31 12:33:48 -07:00
Miss Islington (bot)
90de322b32
[3.12] gh-126083: Fix a reference leak in asyncio.Task when reinitializing with new non-None context (GH-126103) (#126230)
gh-126083: Fix a reference leak in `asyncio.Task` when reinitializing with new non-`None` context (GH-126103)
(cherry picked from commit d07dcce693)

Co-authored-by: Nico-Posada <102486290+Nico-Posada@users.noreply.github.com>
2024-10-31 08:19:56 +00:00
Miss Islington (bot)
bc9ae4a1ca
[3.12] gh-126106: Fix NULL possible derefrence in Modules/_ssl.c (GH-126111) (#126117)
gh-126106: Fix `NULL` possible derefrence in `Modules/_ssl.c` (GH-126111)
(cherry picked from commit a64a1c9206)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-29 09:26:28 +00:00
Miss Islington (bot)
a8472fdbcd
[3.12] Align functools.reduce() docstring with PEP-257 (GH-126045) (#126114)
Yak-shave in preparation for Argument Clinic adaption in gh-125999.

(cherry picked from commit 9b14083497)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2024-10-29 10:13:52 +01:00
Miss Islington (bot)
9f35fbc068
[3.12] gh-126035: add missing whitespace to *Py_EnterRecursiveCall() messages (GH-126036) (#126059)
(cherry picked from commit 19e93e2e26)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-27 22:12:20 +00:00
Miss Islington (bot)
4fc1da1b27
[3.12] gh-125966: fix use-after-free on fut->fut_callback0 due to an evil callback's __eq__ in asyncio (GH-125967) (#126048)
gh-125966: fix use-after-free on `fut->fut_callback0` due to an evil callback's `__eq__` in asyncio (GH-125967)
(cherry picked from commit ed5059eeb1)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-27 17:32:11 +00:00
Miss Islington (bot)
fdedb2618a
[3.12] gh-125984: fix use-after-free on fut->fut_{callback,context}0 due to an evil loop.__getattribute__ (GH-126003) (#126044)
gh-125984: fix use-after-free on `fut->fut_{callback,context}0` due to an evil `loop.__getattribute__` (GH-126003)
(cherry picked from commit f819d4301d)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-27 15:23:07 +00:00
Miss Islington (bot)
f6682fbe49
[3.12] gh-125969: fix OOB in future_schedule_callbacks due to an evil call_soon (GH-125970) (#125992)
gh-125969: fix OOB in `future_schedule_callbacks` due to an evil `call_soon` (GH-125970)
(cherry picked from commit c5b99f5c2c)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2024-10-25 18:38:59 +00:00
Miss Islington (bot)
42927f7f25
[3.12] GH-125789: fix fut._callbacks to always return a copy of callbacks (GH-125922) (#125977)
GH-125789: fix `fut._callbacks` to always return a copy of callbacks (GH-125922)

Fix `asyncio.Future._callbacks` to always return a copy of the internal list of callbacks to avoid mutation from user code affecting the internal state.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
(cherry picked from commit cae853e3b4)
2024-10-25 19:32:46 +05:30
Miss Islington (bot)
0009651d8e
[3.12] gh-124969: Make locale.nl_langinfo(locale.ALT_DIGITS) returning a string again (GH-125774) (GH-125805)
This is a follow up of GH-124974. Only Glibc needed a fix.
Now the returned value is a string consisting of semicolon-separated
symbols on all Posix platforms.
(cherry picked from commit dcc4fb2c90)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-10-21 19:24:45 +00:00
Miss Islington (bot)
232b303e4c
[3.12] gh-52551: Fix encoding issues in strftime() (GH-125193) (GH-125657) (GH-125661)
Fix time.strftime(), the strftime() method and formatting of the
datetime classes datetime, date and time.

* Characters not encodable in the current locale are now acceptable in
  the format string.
* Surrogate pairs and sequence of surrogatescape-encoded bytes are no
  longer recombinated.
* Embedded null character no longer terminates the format string.

This fixes also gh-78662 and gh-124531.

(cherry picked from commit 08ccbb9b3f)
(cherry picked from commit ad3eac1963)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-10-17 20:04:48 +00:00
Jelle Zijlstra
4ab19f912d
[3.12] gh-124917: Allow keyword args to os.path.exists/lexists on Windows (GH-124918) (#125334)
(cherry picked from commit cc2938a189)
2024-10-11 15:18:46 -07:00
Miss Islington (bot)
171ebcd4df
[3.12] [3.13] gh-124969: Fix locale.nl_langinfo(locale.ALT_DIGITS) (GH-124974) (GH-125232) (GH-125284)
(cherry picked from commit 26a93189e4)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Returns a tuple of up to 100 strings for ALT_DIGITS lookup (an empty tuple on most locales).
Previously it returned the first item of that tuple or an empty string.
(cherry picked from commit 21c04e1a97)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-10-11 09:37:55 +03:00
Sergey B Kirpichev
67f8302b9c
[3.12] gh-125118: don't copy arbitrary values to _Bool in the struct module (GH-125169) (#125265)
memcopy'ing arbitrary values to _Bool variable triggers undefined
behaviour. Avoid this.
We assume that `false` is represented by all zero bytes.

Credits to Alex Gaynor.

(cherry picked from commit 87d7315ac5)

Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-10-10 14:56:49 +00:00
Raymond Hettinger
cf2532b39d
[3.12] Tee of tee was not producing n independent iterators (gh-123884) (gh-125153) 2024-10-08 20:16:18 +00:00
Peter Bierma
8dce4918ab
[3.12] gh-120378: Fix crash caused by integer overflow in curses (GH-124555) (#124911)
This is actually an upstream problem in curses, and has been reported
to them already:
https://lists.gnu.org/archive/html/bug-ncurses/2024-09/msg00101.html

This is a nice workaround in the meantime to prevent the segfault.

(cherry picked from commit c2ba931318)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-10-02 21:40:49 +00:00
Serhiy Storchaka
829cdf06d4
[3.12] gh-123978: Remove broken time.thread_time() on NetBSD (GH-124116) (GH-124427)
(cherry picked from commit e670a113b5)
2024-10-02 11:02:14 -07:00
Miss Islington (bot)
186cc407e2
[3.12] gh-116810: fix memory leak in ssl module (GH-123249) (GH-124801)
gh-116810: fix memory leak in ssl module (GH-123249)

Resolve a memory leak introduced in CPython 3.10's :mod:`ssl` when the :attr:`ssl.SSLSocket.session` property was accessed. Speeds up read and write access to said property by no longer unnecessarily cloning session objects via serialization.

(cherry picked from commit 7e7223e18f)

Co-authored-by: Jeffrey R. Van Voorst <jeff.vanvoorst@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Antoine Pitrou <antoine@python.org>
2024-09-30 20:02:13 +00:00
Petr Viktorin
49f6beb56a
[3.12] gh-113993: Make interned strings mortal (GH-120520, GH-121364, GH-121903, GH-122303) (#123065)
This backports several PRs for gh-113993, making interned strings mortal so they can be garbage-collected when no longer needed.

* Allow interned strings to be mortal, and fix related issues (GH-120520)

  * Add an InternalDocs file describing how interning should work and how to use it.

  * Add internal functions to *explicitly* request what kind of interning is done:
    - `_PyUnicode_InternMortal`
    - `_PyUnicode_InternImmortal`
    - `_PyUnicode_InternStatic`

  * Switch uses of `PyUnicode_InternInPlace` to those.

  * Disallow using `_Py_SetImmortal` on strings directly.
    You should use `_PyUnicode_InternImmortal` instead:
    - Strings should be interned before immortalization, otherwise you're possibly
      interning a immortalizing copy.
    - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to
      `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in
      backports, as they are now part of public API and version-specific ABI.

  * Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery.

   Make sure the statically allocated string singletons are unique. This means these sets are now disjoint:
    - `_Py_ID`
    - `_Py_STR` (including the empty string)
    - one-character latin-1 singletons

    Now, when you intern a singleton, that exact singleton will be interned.

  * Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic).

  * Intern `_Py_STR` singletons at startup.

  * Beef up the tests. Cover internal details (marked with `@cpython_only`).

  * Add lots of assertions

* Don't immortalize in PyUnicode_InternInPlace; keep immortalizing in other API (GH-121364)

  * Switch PyUnicode_InternInPlace to _PyUnicode_InternMortal, clarify docs

  * Document immortality in some functions that take `const char *`

  This is PyUnicode_InternFromString;
  PyDict_SetItemString, PyObject_SetAttrString;
  PyObject_DelAttrString; PyUnicode_InternFromString;
  and the PyModule_Add convenience functions.

  Always point out a non-immortalizing alternative.

  * Don't immortalize user-provided attr names in _ctypes

* Immortalize names in code objects to avoid crash (GH-121903)

* Intern latin-1 one-byte strings at startup (GH-122303)

There are some 3.12-specific changes, mainly to allow statically allocated strings in deepfreeze. (In 3.13, deepfreeze switched to the general `_Py_ID`/`_Py_STR`.)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2024-09-27 13:28:48 -07:00
Neil Schemenauer
69fd1f218c
[3.12] gh-116510: Fix crash during sub-interpreter shutdown (gh-124536)
Fix a bug that can cause a crash when sub-interpreters use "basic"
single-phase extension modules.  Shared objects could refer to PyGC_Head
nodes that had been freed as part of interpreter shutdown.
2024-09-26 17:50:46 -07:00
Miss Islington (bot)
6644cd2c1b
[3.12] gh-124248: Fix crash in struct when processing 0p fields (GH-124251) (#124278)
gh-124248: Fix crash in struct when processing 0p fields (GH-124251)
(cherry picked from commit 63f196090f)

Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
2024-09-20 10:29:43 +00:00
Miss Islington (bot)
708173c35e
[3.12] Revert "gh-123974: Fix time.get_clock_info() on NetBSD (GH-123975)" (GH-124115) (GH-124200)
This reverts commit b1d6f8a2ee.
(cherry picked from commit 79a7410236)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-09-18 06:47:17 +00:00
Sergey B Kirpichev
c7a94e77bc
[3.12] gh-123836: workaround fmod(x, y) bug on Windows (GH-124171) (#124186)
Buildbot failure on Windows 10 with MSC v.1916 64 bit (AMD64):
FAIL: testFmod (test.test_math.MathTests.testFmod)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 605, in testFmod
    self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 258, in ftest
    self.fail("{}: {}".format(name, failure))
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: fmod(-10, 1): expected -0.0, got 0.0 (zero has wrong sign)

Here Windows loose sign of the result; if y is nonzero, the result
should have the same sign as x.

This amends commit 28aea5d07d.
(cherry picked from commit f4dd440210)
2024-09-17 21:44:52 +02:00
Miss Islington (bot)
446203e122
[3.12] gh-121023: Improve _xxtestfuzz/README.rst (GH-121024) (#124141)
gh-121023: Improve `_xxtestfuzz/README.rst` (GH-121024)
(cherry picked from commit a9c2bc1634)

Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Illia Volochii <illia.volochii@gmail.com>
2024-09-16 20:29:02 +00:00
Miss Islington (bot)
b2a7d718e3
[3.12] gh-123974: Fix time.get_clock_info() on NetBSD (GH-123975) (#124073)
gh-123974: Fix time.get_clock_info() on NetBSD (GH-123975)

Fix OSError for thread_time clock on NetBSD by setting default resolution.
(cherry picked from commit b1d6f8a2ee)

Co-authored-by: Furkan Onder <furkanonder@protonmail.com>
2024-09-13 20:54:09 +00:00
Miss Islington (bot)
58e01a1c7f
[3.12] gh-123431: Harmonize extension code checks in pickle (GH-123434) (#123460)
This checks are redundant in normal circumstances and can only work if
the extension registry was intentionally broken.

(cherry picked from commit 0c3ea30238)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-09-06 15:50:27 +02:00
Miss Islington (bot)
747abc00d0
[3.12] gh-123213: Fixed xml.etree.ElementTree.Element.extend and assignment to no longer hide exceptions (GH-123214) (#123258)
Co-authored-by: Bar Harel <bharel@barharel.com>
2024-09-06 11:51:18 +03:00
Sergey B Kirpichev
1d8ab25742
[3.12] gh-111495: Add tests for PyNumber C API (GH-111996) (#123376)
(cherry picked from commit 2f20f5a9bc)
2024-09-06 00:51:26 +02:00
Sergey B Kirpichev
625072f76e
[3.12] gh-111495: Add tests for PyTuple C API (GH-118757) (#123379)
(cherry picked from commit dbc1752d41)

Co-authored-by: kalyanr <kalyan.ben10@live.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-09-06 00:51:02 +02:00
Miss Islington (bot)
3cf7d334f2
[3.12] gh-123678: Upgrade libexpat 2.6.3 (GH-123689) (GH-123708)
gh-123678: Upgrade libexpat 2.6.3 (GH-123689)

Upgrade libexpat 2.6.3
(cherry picked from commit 40bdb0deee)

Co-authored-by: Seth Michael Larson <seth@python.org>
2024-09-04 20:19:33 +00:00
Miss Islington (bot)
41090b7ba0
[3.12] gh-112182: Replace StopIteration with RuntimeError for future (GH-113220) (GH-123033)
When an `StopIteration` raises into `asyncio.Future`, this will cause
a thread to hang. This commit address this by not raising an exception
and silently transforming the `StopIteration` with a `RuntimeError`,
which the caller can reconstruct from `fut.exception().__cause__`
(cherry picked from commit 4826d52338)

Co-authored-by: Jamie Phan <jamie@ordinarylab.dev>
2024-08-15 15:34:53 +00:00
Miss Islington (bot)
9d7209fc93
[3.12] gh-113785: csv: fields starting with escapechar are not quoted (GH-122110) (GH-122259)
(cherry picked from commit a3327dbfd4)

Co-authored-by: Mikołaj Kuranowski <mkuranowski@gmail.com>
2024-08-09 16:04:29 +00:00
Victor Stinner
c57a33d006
[3.12] gh-122695: Fix double-free when using gc.get_referents with a freed _asyncio.FutureIter (#122837) (#122859)
[3.13] gh-122695: Fix double-free when using `gc.get_referents` with a freed `_asyncio.FutureIter` (#122837)

* Backport #122834 for 3.13

(cherry picked from commit e8fb088dba)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-08-09 14:33:24 +00:00
Serhiy Storchaka
f2cc8ad989
[3.12] gh-118814: Fix the TypeVar constructor when name is passed by keyword (GH-122664) (GH-122807)
Fix _PyArg_UnpackKeywordsWithVararg for the case when argument for
positional-or-keyword parameter is passed by keyword.
There was only one such case in the stdlib -- the TypeVar constructor.
(cherry picked from commit 540fcc62f5)
2024-08-08 09:49:50 +03:00
Miss Islington (bot)
8f4892ac52
gh-100256: Skip inaccessible registry keys in the WinAPI mimetype implementation (GH-122047)
(cherry picked from commit 0bd93755f3)

Co-authored-by: Lucas Esposito <LucasEsposito@users.noreply.github.com>
2024-08-07 19:39:51 +01:00
Gregory P. Smith
b31764104e
[3.12] gh-119577: Adjust DeprecationWarning when testing element truth values in Element tree (GH-119762) (#120190)
gh-119577: Adjust DeprecationWarning when testing element truth values in ElementTree (GH-119762)

Adjust DeprecationWarning when testing element truth values in
ElementTree, we're planning to go with the more natural True return
rather than a disruptive harder to code around exception raise, and are
deferring the behavior change for a few more releases.

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
2024-08-06 17:20:06 +00:00
Miss Islington (bot)
bad84975ff
[3.12] gh-122311: Fix a refleak in pickle (GH-122411) (GH-122416)
(cherry picked from commit 68840e91ac)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-07-29 19:10:46 +00:00
Serhiy Storchaka
e6878fc3c8
Revert "[3.12] gh-120713: Normalize year with century for datetime.strftime (GH-120820) (GH-121145)" (GH-122409)
This reverts commit 027902b56f.
2024-07-29 21:55:12 +03:00
Miss Islington (bot)
a3076c734d
[3.12] gh-122311: Fix some error messages in pickle (GH-122386) (GH-122388)
(cherry picked from commit 3b034d26eb)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-07-29 12:27:34 +03:00
Miss Islington (bot)
102dc44a0a
[3.12] gh-122332: Fix missing NULL check in asyncio.Task.get_coro (GH-122338) (#122345)
gh-122332: Fix missing `NULL` check in `asyncio.Task.get_coro` (GH-122338)
(cherry picked from commit c08696286f)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-07-27 12:36:40 +05:30