Commit Graph

6661 Commits

Author SHA1 Message Date
Miss Islington (bot) e1c396d164
[3.9] gh-105184: document that marshal functions can fail and need to be checked with PyErr_Occurred (GH-105185) (#105221)
(cherry picked from commit ee26ca13a1)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2023-06-05 17:42:16 +02:00
Kumar Aditya 7cb3a44747
[3.9] GH-102126: fix deadlock at shutdown when clearing thread states (GH-102222) (#102236)
(cherry picked from commit 5f11478ce7)
2023-03-28 10:55:36 +02:00
Gregory P. Smith cf71e19297
[3.9] Correct CVE-2020-10735 documentation (GH-100306). (#100697)
(cherry picked from commit 1cf3d78c92)
(cherry picked from commit 88fe8d701a)

Co-authored-by: Jeremy Paige <ucodery@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-01-20 23:20:32 +01:00
Benjamin Peterson 08210c62e9
[3.9] Update copyright years to 2023. (gh-100851)
* [3.9] Update copyright years to 2023. (gh-100848).
(cherry picked from commit 11f99323c2)

Co-authored-by: Benjamin Peterson <benjamin@python.org>

* Update additional copyright years to 2023.

Co-authored-by: Ned Deily <nad@python.org>
2023-01-08 17:00:10 -06:00
Steve Dower 7b98207aa4
[3.9] gh-87604: Avoid publishing list of active per-interpreter audit hooks via the gc module (GH-99373) (GH-99493) 2022-11-21 19:13:33 +01:00
Miss Islington (bot) 358b7a4454
[3.9] gh-96848: Fix -X int_max_str_digits option parsing (GH-96988) (GH-97574)
gh-96848: Fix -X int_max_str_digits option parsing (GH-96988)

Fix command line parsing: reject "-X int_max_str_digits" option with
no value (invalid) when the PYTHONINTMAXSTRDIGITS environment
variable is set to a valid limit.
(cherry picked from commit 41351662bc)

Co-authored-by: Victor Stinner <vstinner@python.org>
2022-10-04 11:57:34 -07:00
Gregory P. Smith cec1e9dfd7
[3.9] gh-95778: CVE-2020-10735: Prevent DoS by very large int() (#96502)
* Correctly pre-check for int-to-str conversion (#96537)

Converting a large enough `int` to a decimal string raises `ValueError` as expected. However, the raise comes _after_ the quadratic-time base-conversion algorithm has run to completion. For effective DOS prevention, we need some kind of check before entering the quadratic-time loop. Oops! =)

The quick fix: essentially we catch _most_ values that exceed the threshold up front. Those that slip through will still be on the small side (read: sufficiently fast), and will get caught by the existing check so that the limit remains exact.

The justification for the current check. The C code check is:
```c
max_str_digits / (3 * PyLong_SHIFT) <= (size_a - 11) / 10
```

In GitHub markdown math-speak, writing $M$ for `max_str_digits`, $L$ for `PyLong_SHIFT` and $s$ for `size_a`, that check is:
$$\left\lfloor\frac{M}{3L}\right\rfloor \le \left\lfloor\frac{s - 11}{10}\right\rfloor$$

From this it follows that
$$\frac{M}{3L} < \frac{s-1}{10}$$
hence that
$$\frac{L(s-1)}{M} > \frac{10}{3} > \log_2(10).$$
So
$$2^{L(s-1)} > 10^M.$$
But our input integer $a$ satisfies $|a| \ge 2^{L(s-1)}$, so $|a|$ is larger than $10^M$. This shows that we don't accidentally capture anything _below_ the intended limit in the check.

<!-- gh-issue-number: gh-95778 -->
* Issue: gh-95778
<!-- /gh-issue-number -->

Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2022-09-05 11:21:03 +02:00
Miss Islington (bot) 95c9c2b9cb
gh-93065: Fix HAMT to iterate correctly over 7-level deep trees (GH-93066) (#93147)
Also while there, clarify a few things about why we reduce the hash to 32 bits.

Co-authored-by: Eli Libman <eli@hyro.ai>
Co-authored-by: Yury Selivanov <yury@edgedb.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>

(cherry picked from commit c1f5c903a7)
2022-05-24 10:52:49 +02:00
Miss Islington (bot) 1d428bb8c9
bpo-46831: Update __build_class__ comment (GH-31522)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit 81d968b7c3)

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
2022-03-02 21:59:57 -08:00
Petr Viktorin 8d239bfdcc
[3.9] bpo-45703: Invalidate _NamespacePath cache on importlib.invalidate_cache (GH-29384) (GH-30922) (GH-31076)
Consider the following directory structure:

    .
    └── PATH1
        └── namespace
            └── sub1
                └── __init__.py

And both PATH1 and PATH2 in sys path:

    $ PYTHONPATH=PATH1:PATH2 python3.11
    >>> import namespace
    >>> import namespace.sub1
    >>> namespace.__path__
    _NamespacePath(['.../PATH1/namespace'])
    >>> ...

While this interpreter still runs, PATH2/namespace/sub2 is created:

    .
    ├── PATH1
    │   └── namespace
    │       └── sub1
    │           └── __init__.py
    └── PATH2
        └── namespace
            └── sub2
                └── __init__.py

The newly created module cannot be imported:

    >>> ...
    >>> namespace.__path__
    _NamespacePath(['.../PATH1/namespace'])
    >>> import namespace.sub2
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'namespace.sub2'

Calling importlib.invalidate_caches() now newly allows to import it:

    >>> import importlib
    >>> importlib.invalidate_caches()
    >>> namespace.__path__
    _NamespacePath(['.../PATH1/namespace'])
    >>> import namespace.sub2
    >>> namespace.__path__
    _NamespacePath(['.../PATH1/namespace', '.../PATH2/namespace'])

This was not previously possible.








Co-Authored-By: Miro Hrončok <miro@hroncok.cz>

Automerge-Triggered-By: GH:encukou
2022-02-02 05:50:43 -08:00
Miss Islington (bot) 17c858e331
Update copyright year to 2022. (GH-30335)
Automerge-Triggered-By: GH:benjaminp
(cherry picked from commit ba00f0d93a)

Co-authored-by: Benjamin Peterson <benjamin@python.org>
2022-01-02 12:34:36 -08:00
Irit Katriel 5b6aa6ce20
bpo-45614: Fix traceback display for exceptions with invalid module name (GH-29726) (GH-29827)
(cherry picked from commit 4dfae6f38e)
2021-11-29 10:11:48 +00:00
Mark Shannon 4296396db0
[3.9] bpo-45806: Fix recovery from stack overflow for 3.9. Again. (GH-29640)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-11-19 19:51:50 +01:00
Sam Gross 87787c8774
[3.9] bpo-42540: reallocation of id_mutex should not force default allocator (GH-29564) (GH-29600)
Unlike the other locks reinitialized by _PyRuntimeState_ReInitThreads,
the "interpreters.main->id_mutex" is not freed by _PyRuntimeState_Fini
and should not force the default raw allocator..
(cherry picked from commit 736684b1bb)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2021-11-17 23:53:33 +01:00
Miss Islington (bot) ac89f8cab7
bpo-45831: _Py_DumpASCII() uses a single write() call if possible (GH-29596) (GH-29597)
If the string is ASCII only and doesn't need to escape characters,
write the whole string with a single write() syscall.
(cherry picked from commit b919d8105c)

Co-authored-by: Victor Stinner <vstinner@python.org>
2021-11-17 22:59:42 +01:00
Miss Islington (bot) aa8c3446c0
bpo-44959: Add fallback to extension modules with '.sl' suffix on HP-UX (GH-27857)
(cherry picked from commit 2396fa6537)

Co-authored-by: Florin Spătar <florin.spatar@gmail.com>
2021-10-22 04:08:50 -07:00
Serhiy Storchaka 7c722e32bf
[3.9] bpo-45461: Fix IncrementalDecoder and StreamReader in the "unicode-escape" codec (GH-28939) (GH-28945)
They support now splitting escape sequences between input chunks.

Add the third parameter "final" in codecs.unicode_escape_decode().
It is True by default to match the former behavior.
(cherry picked from commit c96d1546b1)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-10-14 20:03:29 +03:00
Miss Islington (bot) 6d4d4ec59f
Fix format string in _PyImport_LoadDynamicModuleWithSpec() (GH-28863)
(cherry picked from commit f79f3b41c8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-10-12 10:10:41 -07:00
Miss Islington (bot) 7d1ae89b84
Handle error when PyUnicode_GetLength returns a negative value. (GH-28859)
(cherry picked from commit 560a79f94e)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
2021-10-11 04:40:57 -07:00
Miss Islington (bot) d57d33c234
Fix a leak in _PyImport_LoadDynamicModuleWithSpec() after failing PySys_Audit() (GH-28862)
(cherry picked from commit 9883ca498d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-10-11 02:43:09 -07:00
Christian Clauss 78efc9aff2
[3.9] Fix typos in the Python directory (GH-28767) (GH-28798)
(cherry picked from commit db693df3e1)

Automerge-Triggered-By: GH:JulienPalard
2021-10-07 07:36:39 -07:00
Łukasz Langa 52d9d3b754
[3.9] bpo-44050: Extension modules can share state when they don't support sub-interpreters. (GH-27794) (GH-28741)
(cherry picked from commit b9bb74871b)

Co-authored-by: Hai Shi <shihai1992@gmail.com>
2021-10-05 22:30:25 +02:00
Serhiy Storchaka e9ce081ec7
[3.9] Remove trailing spaces (GH-28710) 2021-10-03 20:04:38 +03:00
Miss Islington (bot) 0e1aeab5d7
bpo-41710: PyThread_acquire_lock_timed() uses sem_clockwait() (GH-28671) (GH-28683)
On Unix, if the sem_clockwait() function is available in the C
library (glibc 2.30 and newer), the threading.Lock.acquire() method
now uses the monotonic clock (time.CLOCK_MONOTONIC) for the timeout,
rather than using the system clock (time.CLOCK_REALTIME), to not be
affected by system clock changes.

configure now checks if the sem_clockwait() function is available.
(cherry picked from commit 6df8c32753)

Co-authored-by: Victor Stinner <vstinner@python.org>
2021-10-01 18:51:15 +02:00
Miss Islington (bot) 5c65834d80
bpo-44219: Release the GIL during isatty syscalls (GH-28250)
Release the GIL while performing isatty() system calls on arbitrary
file descriptors. In particular, this affects os.isatty(),
os.device_encoding() and io.TextIOWrapper. By extension,
io.open() in text mode is also affected.
(cherry picked from commit 06148b1870)

Co-authored-by: Vincent Michel <vxgmichel@gmail.com>
2021-09-09 06:40:42 -07:00
Miss Islington (bot) 41c2374024
[3.9] bpo-45083: Include the exception class qualname when formatting an exception (GH-28119) (GH-28135)
* bpo-45083: Include the exception class qualname when formatting an exception (GH-28119)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
(cherry picked from commit b4b6342848)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-09-03 18:56:05 +02:00
Miss Islington (bot) 720aef48b5
bpo-44449: faulthandler don't modify frame refcnt (GH-27850)
Fix a crash in the signal handler of the faulthandler module: no
longer modify the reference count of frame objects.
(cherry picked from commit fe997e1a67)

Co-authored-by: Victor Stinner <vstinner@python.org>
2021-08-30 06:56:03 -07:00
Miss Islington (bot) 6f4cdeddb9
bpo-25782: avoid hang in PyErr_SetObject when current exception has a cycle in its context chain (GH-27626) (GH-27707)
Co-authored-by: Dennis Sweeney 36520290+sweeneyde@users.noreply.github.com
(cherry picked from commit d5c217475c)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2021-08-10 13:08:41 +02:00
Miss Islington (bot) ed718e9b07
bpo-44856: Possible reference leak in error paths of update_bases() and __build_class__ (GH-27647) (GH-27651)
(cherry picked from commit a40675c659)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-08-07 13:17:41 +02:00
Miss Islington (bot) 791c28a56f
bpo-44849: Fix os.set_inheritable() on FreeBSD 14 with O_PATH (GH-27623)
Fix the os.set_inheritable() function on FreeBSD 14 for file
descriptor opened with the O_PATH flag: ignore the EBADF error on
ioctl(), fallback on the fcntl() implementation.
(cherry picked from commit c24896c0e3)

Co-authored-by: Victor Stinner <vstinner@python.org>
2021-08-06 06:42:51 -07:00
Miss Islington (bot) 0b551db04a
bpo-39091: Fix segfault when Exception constructor returns non-exception for gen.throw. (GH-17658) (GH-27573)
Co-authored-by: Benjamin Peterson <benjamin@python.org>
(cherry picked from commit 83ca46b778)

Co-authored-by: Noah <33094578+coolreader18@users.noreply.github.com>
2021-08-03 12:10:54 +02:00
Mark Shannon 7ebd7465a5
Set line number of END_ASYNC_FOR so that it doesn't show in traces. (GH-27255) 2021-07-20 12:09:56 +02:00
Miss Islington (bot) 6fb4248cd9
bpo-44472: Fix ltrace functionality when exceptions are raised (GH-26822) (#26831)
(cherry picked from commit 06cda808f1)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-07-12 17:11:10 +02:00
Steve Dower 863e3d5c7e
bpo-41180: Replace marshal code.__new__ audit event with marshal.load[s] and marshal.dumps (GH-26971) 2021-06-30 18:52:39 +01:00
Victor Stinner 5ed7827b16
bpo-44441: _PyImport_Fini2() resets PyImport_Inittab (GH-26874) (GH-26878)
Py_RunMain() now resets PyImport_Inittab to its initial value at
exit. It must be possible to call PyImport_AppendInittab() or
PyImport_ExtendInittab() at each Python initialization.

(cherry picked from commit 489699ca05)
2021-06-23 17:47:33 +02:00
Miss Islington (bot) 57b3ca7f0a
bpo-41299: Reduce lag in Windows threading timeouts by using a higher precision time source (GH-26568)
(cherry picked from commit 449e6f0ef3)

Co-authored-by: Ryan Hileman <lunixbochs@gmail.com>
2021-06-11 15:03:10 -07:00
Batuhan Taskaya de58b319af
[3.9] bpo-11105: Do not crash when compiling recursive ASTs (GH-20594) (GH-26522)
When compiling an AST object with a direct / indirect reference
cycles, on the conversion phase because of exceeding amount of
calls, a segfault was raised. This patch adds recursion guards to
places for preventing user inputs to not to crash AST but instead
raise a RecursionError..
(cherry picked from commit f3491242e4)

Co-authored-by: Batuhan Taskaya <batuhan@python.org>
2021-06-03 22:22:34 +01:00
Jakub Kulík d3cc68900d
[3.9] bpo-43667: Fix broken Unicode encoding in non-UTF locales on Solaris (GH-25096) (GH-25847)
(cherry picked from commit 9032cf5cb1)

Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
2021-05-21 16:59:39 +02:00
Miss Islington (bot) 133013e8a1
bpo-28146: Fix a confusing error message in str.format() (GH-24213)
Automerge-Triggered-By: GH:pitrou
(cherry picked from commit 4aeee0b47b)

Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
2021-05-13 14:35:30 -07:00
Steve Dower 23822e2c65
bpo-44070: No longer eagerly makes import filenames absolute, except for extension modules (GH-26025) 2021-05-10 23:45:50 +01:00
Steve Dower bb2f3ff7a8
bpo-42800: Add audit events for f_code and tb_frame (GH-24182)
Accessing the following attributes will now fire PEP 578 style audit hooks as (object.__getattr__, obj, name):
* PyTracebackObject: tb_frame
* PyFrameObject: f_code
* PyGenObject: gi_code, gi_frame
* PyCoroObject: cr_code, cr_frame
* PyAsyncGenObject: ag_code, ag_frame
2021-05-03 14:06:36 +01:00
Steve Dower 0af99b44ed
bpo-43105: Importlib now resolves relative paths when creating module spec objects from file locations (GH-25121) 2021-04-07 12:35:36 +01:00
Gregory P. Smith c7b0feca25
[3.9] bpo-43710: Rollback the 3.9 bpo-42500 fix, it broke the ABI in 3.9.3 (#25179)
This reverts commit 8b795ab554.

It changed the PyThreadState structure size, breaking the ABI in 3.9.3.
2021-04-04 13:02:29 +02:00
Miss Islington (bot) ff4715a733
bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075) (GH-25083)
(cherry picked from commit 09b90a037d)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-03-30 00:24:33 +01:00
Antoine Pitrou ac17ed60f2
[3.9] bpo-43517: Fix false positive in detection of circular imports (GH-24895) (GH-24948)
(cherry picked from commit 2fd16ef406)

Co-authored-by: Antoine Pitrou <antoine@python.org>

Automerge-Triggered-By: GH:pitrou
2021-03-20 12:40:18 -07:00
Miss Islington (bot) aa967ec4d4
bpo-35883: Py_DecodeLocale() escapes invalid Unicode characters (GH-24843)
Python no longer fails at startup with a fatal error if a command
line argument contains an invalid Unicode character.

The Py_DecodeLocale() function now escapes byte sequences which would
be decoded as Unicode characters outside the [U+0000; U+10ffff]
range.

Use MAX_UNICODE constant in unicodeobject.c.
(cherry picked from commit 9976834f80)

Co-authored-by: Victor Stinner <vstinner@python.org>
2021-03-17 14:11:14 -07:00
Serhiy Storchaka 651fc30af7
bpo-43499: Silence compiler warnings about using legacy C API on Windows (GH-24873) 2021-03-16 08:03:37 +02:00
Mark Shannon 8b795ab554
bpo-42500: Fix recursion in or after except (GH-23568) (#24501)
* Use counter, rather boolean state when handling soft overflows.

(cherry picked from commit 4e7a69bdb6)
2021-03-02 11:36:38 +01:00
cptpcrd 6893523bed
bpo-42780: Fix set_inheritable() for O_PATH file descriptors on Linux (GH-24172) (GH-24278)
(cherry picked from commit 7dc71c425c)
2021-01-21 11:46:35 +01:00
Miss Islington (bot) fa12749bcd
Bring Python into the new year. (GH-24036)
(cherry picked from commit de6f20a6de)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
2021-01-01 09:27:48 -08:00