Commit Graph

7523 Commits

Author SHA1 Message Date
Serhiy Storchaka b8b3e6afc0
[3.11] gh-99612: Fix PyUnicode_DecodeUTF8Stateful() for ASCII-only data (GH-99613) (GH-107224)
Previously *consumed was not set in this case.
(cherry picked from commit f08e52ccb0)
2023-07-25 14:15:14 +03:00
Serhiy Storchaka fb04874053
[3.11] gh-106719: Fix __annotations__ getter and setter in the type and module types (GH-106720) (GH-106850)
No longer suppress arbitrary errors. Simplify the code.
(cherry picked from commit e1c295e3da)
2023-07-18 10:19:45 +03:00
Dennis Sweeney d488970ae6
[3.11] gh-105235: Prevent reading outside buffer during mmap.find() (… (#106710)
[3.11] gh-105235: Prevent reading outside buffer during mmap.find() (GH-105252)

* Add a special case for s[-m:] == p in _PyBytes_Find

* Add tests for _PyBytes_Find

* Make sure that start <= end in mmap.find.
(cherry picked from commit ab86426a34)
2023-07-14 22:17:09 -04:00
Miss Islington (bot) 8623812fdc
[3.11] Fix possible refleak in CodeType.replace() (GH-106243) (GH-106245)
Fix possible refleak in CodeType.replace() (GH-106243)

A reference to c_code was leaked if PySys_Audit() failed.
(cherry picked from commit 3c70d467c1)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-06-29 21:41:18 +03:00
Serhiy Storchaka dbe416b82b
[3.11] gh-106033: Get rid of new occurrences of PyDict_GetItem and Py… (#106040)
[3.11] gh-106033: Get rid of new occurrences of PyDict_GetItem and PyObject_HasAttr (GH-106034)

These functions are broken by design because they discard any exceptions raised
inside, including MemoryError and KeyboardInterrupt.  They should not be
used in new code..
(cherry picked from commit 1d33d53780)
2023-06-24 16:41:02 -07:00
Miss Islington (bot) 91877478ed
[3.11] gh-105375: Improve error handling in PyUnicode_BuildEncodingMap() (GH-105491) (#105662)
Bail on first error to prevent exceptions from possibly being overwritten.
(cherry picked from commit 555be81026)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-06-11 20:01:52 +00:00
Brandt Bucher 4ade7c3369
[3.11] Fix refleak in super_descr_get (GH-104440)
(cherry picked from commit a781484c8e)
2023-05-12 22:29:02 +00:00
Brandt Bucher b90c922f3f
[3.11] GH-94841: Fix usage of Py_ALWAYS_INLINE (GH-104439) 2023-05-12 22:06:29 +00:00
Lysandros Nikolaou a09d3901a5
[3.11] gh-96670: Raise SyntaxError when parsing NULL bytes (GH-97594) (#104195) 2023-05-07 11:12:04 +01:00
Miss Islington (bot) 15ffcf76e1
[3.11] gh-104018: remove unused format "z" handling in string formatfloat() (GH-104107) (#104260)
gh-104018: remove unused format "z" handling in string formatfloat() (GH-104107)

This is a cleanup overlooked in PR GH-104033.
(cherry picked from commit 69621d1b09)

Co-authored-by: John Belmonte <john@neggie.net>
2023-05-07 05:06:06 +00:00
Irit Katriel 5386730cdd
[3.11] gh-103590: do not wrap a single exception raised from a try-except* (#104094) 2023-05-02 19:24:02 +01:00
Miss Islington (bot) 10db28bfcf
[3.11] gh-104018: disallow "z" format specifier in %-format of byte strings (GH-104033) (#104058)
gh-104018: disallow "z" format specifier in %-format of byte strings (GH-104033)

PEP-0682 specified that %-formatting would not support the "z" specifier,
but it was unintentionally allowed for bytes. This PR makes use of the "z"
flag an error for %-formatting in a bytestring.

Issue: GH-104018

---------

(cherry picked from commit 3ed8c88290)

Co-authored-by: John Belmonte <john@neggie.net>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2023-05-01 20:18:29 +00:00
Miss Islington (bot) c8de883bcb
[3.11] gh-99184: Bypass instance attribute access in `repr` of `weakref.ref` (GH-99244) (#103789)
gh-99184: Bypass instance attribute access in `repr` of `weakref.ref` (GH-99244)
(cherry picked from commit 58b6be3791)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-04-24 19:58:55 +00:00
Miss Islington (bot) e715da6db1
gh-87864: Use correct function definition syntax in the docs (GH-103312)
(cherry picked from commit 50b4b15984)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-04-11 07:19:33 -07:00
Miss Islington (bot) f967aee4fb
gh-102701: Fix overflow in dictobject.c (GH-102750)
(cherry picked from commit 65fb7c4055)

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
2023-03-17 07:54:18 -07:00
Miss Islington (bot) 06a3bb8c94
gh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (GH-101896)
(cherry picked from commit 705487c655)

Co-authored-by: Raj <51259329+workingpayload@users.noreply.github.com>
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
2023-03-04 06:46:17 -08:00
Miss Islington (bot) 64d3715de8
gh-101765: unicodeobject: use Py_XDECREF correctly (GH-102283)
(cherry picked from commit 8d0f09b1be)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-02-26 15:09:18 -08:00
Jelle Zijlstra b36c49899b
[3.11] gh-101765: Fix refcount issues in list and unicode pickling (GH-102265) (#102268)
(cherry picked from commit d71edbd1b7)
2023-02-25 16:38:19 -08:00
Ionite 5d461225a5
[3.11] gh-101765: Fix SystemError / segmentation fault in iter `__reduce__` when internal access of `builtins.__dict__` exhausts the iterator (GH-101769) (#102228)
(cherry picked from commit 54dfa14c5a)
2023-02-24 19:49:59 -08:00
Erlend E. Aasland c5c12381b3
[3.11] GH-101696: invalidate type version tag in `_PyStaticType_Dealloc` (GH-101697) (#101722)
[3.11] GH-101696: invalidate type version tag in `_PyStaticType_Dealloc` (GH-101697).
(cherry picked from commit d9de079248)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-02-11 14:00:42 +05:30
Łukasz Langa 955ba2839b
[3.11] gh-101072: support default and kw default in PyEval_EvalCodeEx for 3.11+ (GH-101127) (#101636)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Matthieu Dartiailh <m.dartiailh@gmail.com>
2023-02-07 13:36:35 +00:00
Mark Dickinson 358b02dac4
[3.11] gh-101266: Revert fix __sizeof__ for subclasses of int (#101638)
Revert "[3.11] gh-101266: Fix __sizeof__ for subclasses of int (GH-101394) (#101579)"

This reverts commit cf89c16486.
2023-02-07 11:44:43 +00:00
Mark Dickinson cf89c16486
[3.11] gh-101266: Fix __sizeof__ for subclasses of int (GH-101394) (#101579)
Fix the behaviour of the `__sizeof__` method (and hence the results returned
by `sys.getsizeof`) for subclasses of `int`. Previously, `int` subclasses gave
identical results to the `int` base class, ignoring the presence of the instance
dictionary.

(Manual backport of #101394 to the Python 3.11 branch.)
2023-02-05 12:18:56 +00:00
Miss Islington (bot) d2aaf818ae
[3.11] gh-101037: Fix potential memory underallocation for zeros of int subtypes (GH-101038) (#101219)
gh-101037: Fix potential memory underallocation for zeros of int subtypes (GH-101038)

This PR fixes object allocation in long_subtype_new to ensure that there's at least one digit in all cases, and makes sure that the value of that digit is copied over from the source long.

Needs backport to 3.11, but not any further: the change to require at least one digit was only introduced for Python 3.11.

Fixes GH-101037.
(cherry picked from commit 401fdf9c85)

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2023-01-21 10:54:09 +00:00
Miss Islington (bot) 63690e9af8
gh-101056: Fix memory leak in `formatfloat()` in `bytesobject.c` (GH-101057)
(cherry picked from commit b1a74a182d)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-01-16 03:12:23 -08:00
Nikita Sobolev 855b1a935e
[3.11] GH-100942: Fix incorrect cast in property_copy(). (GH-100965). (#101008)
(cherry picked from commit 94fc7706b7)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
2023-01-15 12:38:25 +05:30
Miss Islington (bot) 50409a2968
[3.11] gh-100637: Fix int and bool __sizeof__ calculation to include the 1 element ob_digit array for 0 and False (GH-100663) (#100717)
gh-100637: Fix int and bool __sizeof__ calculation to include the 1 element ob_digit array for 0 and False (GH-100663)

Fixes behaviour where int (and subtypes like bool) __sizeof__ under-reports true size as it did not take into account the size 1 `ob_digit` array for the zero int.

(cherry picked from commit d7e7f79ca7)

Co-authored-by: Ionite <dev@ionite.io>
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2023-01-03 17:59:40 +00:00
Bill Fisher 57e727af3f
[3.11] gh-99110: Initialize frame->previous in init_frame to fix segmentation fault (GH-100182) (#100478)
(cherry picked from commit 88d565f32a)

Co-authored-by: Bill Fisher <william.w.fisher@gmail.com>
2022-12-24 11:17:10 +05:30
Miss Islington (bot) 17bc55e043
clarify the 4300-digit limit on int-str conversion (GH-100175)
(cherry picked from commit 935ef59321)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
2022-12-12 04:06:48 -08:00
Ken Jin 9e38553132
[3.11] gh-99886: Fix crash when freeing objects with managed dictionaries (#99902)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2022-12-04 14:41:23 +08:00
Victor Stinner 9707bf228e
gh-99845: _PyObject_DictPointer(): fix dictoffset cast (#99922)
Cast size_t to Py_ssize_t, rather than casting it to long. On 64-bit
Windows, long is 32-bit whereas Py_ssize_t is 64-bit.
2022-12-01 14:07:58 +01:00
Miss Islington (bot) 82ab9e6b79
gh-99553: fix bug where an ExceptionGroup subclass can wrap a BaseException (GH-99572)
(cherry picked from commit c8c6113398)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2022-11-18 08:10:55 -08:00
Miss Islington (bot) bbac9a8bcc
gh-99443: `descr_set_trampoline_call` return type should be `int` not `PyObject*` (GH-99444)
(cherry picked from commit bc390dd935)

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
2022-11-16 15:50:50 -08:00
Miss Islington (bot) 47f4a18be0
gh-99181: fix except* on unhashable exceptions (GH-99192)
(cherry picked from commit c43714fbcd)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2022-11-08 01:58:45 -08:00
Miss Islington (bot) 20c258c692
gh-98852: Fix subscription of type aliases (GH-98920)
Fix subscription of type aliases containing bare generic types or types
like TypeVar: for example tuple[A, T][int] and tuple[TypeVar, T][int],
where A is a generic type, and T is a type variable.
(cherry picked from commit 0e15c31c7e)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-11-01 01:01:28 -07:00
Dennis Sweeney 5efe2eead3
[3.11] gh-98783: Fix crashes when `str` subclasses are used in `_PyUnicode_Equal` (GH-98806) (#98871)
* gh-98783: Fix crashes when `str` subclasses are used in `_PyUnicode_Equal` (GH-98806)
(cherry picked from commit 76f989dc3e)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-10-30 14:30:08 -04:00
Miss Islington (bot) cfbc01fe48
obmalloc: Remove unused variable. (GH-98770)
(cherry picked from commit bded5edd9a)

Co-authored-by: Benjamin Peterson <benjamin@python.org>
2022-10-27 09:30:46 -07:00
Miss Islington (bot) 33cf0a604c
gh-97943: PyFunction_GetAnnotations should return a borrowed reference. (GH-97949)
(cherry picked from commit 6bfb0be804)

Co-authored-by: larryhastings <larry@hastings.org>
2022-10-06 13:03:32 -07:00
Miss Islington (bot) 2b248b0ab5
gh-95196: Disable incorrect pickling of the C implemented classmethod descriptors (GH-96383)
(cherry picked from commit 77f0249308)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-10-05 04:59:09 -07:00
Miss Islington (bot) 015b49ac05
[3.11] GH-97779: Ensure that *all* frame objects are backed by "complete" frames (GH-97886)
(cherry picked from commit 0ff8fd6583)

Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
2022-10-04 22:46:34 -07:00
Miss Islington (bot) dbde686a49
gh-97591: In `Exception.__setstate__()` acquire strong references before calling `tp_hash` slot (GH-97700)
(cherry picked from commit d639438609)

Co-authored-by: Ofey Chan <ofey206@gmail.com>
2022-10-01 21:19:57 -07:00
Miss Islington (bot) 7d60d10b63
gh-97616: list_resize() checks for integer overflow (GH-97617)
Fix multiplying a list by an integer (list *= int): detect the
integer overflow when the new allocated length is close to the
maximum size.  Issue reported by Jordan Limor.

list_resize() now checks for integer overflow before multiplying the
new allocated length by the list item size (sizeof(PyObject*)).
(cherry picked from commit a5f092f3c4)

Co-authored-by: Victor Stinner <vstinner@python.org>
2022-09-28 15:28:38 -07:00
Miss Islington (bot) 92a0e81fe1
gh-95778: Mention sys.set_int_max_str_digits() in error message (GH-96874)
When ValueError is raised if an integer is larger than the limit,
mention sys.set_int_max_str_digits() in the error message.
(cherry picked from commit e841ffc915)

Co-authored-by: Victor Stinner <vstinner@python.org>
2022-09-16 11:33:27 -07:00
Christian Heimes bc337a7766
[3.11] gh-96005: Handle WASI ENOTCAPABLE in getpath (GH-96006) (GH-96034) (GH-96038)
- On WASI `ENOTCAPABLE` is now mapped to `PermissionError`.
- The `errno` modules exposes the new error number.
- `getpath.py` now ignores `PermissionError` when it cannot open landmark
  files `pybuilddir.txt` and `pyenv.cfg`.
2022-09-13 13:00:45 +02:00
Miss Islington (bot) 99919d4e8a
gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (GH-96353)
(cherry picked from commit b9634ac776)

Co-authored-by: philg314 <110174000+philg314@users.noreply.github.com>
2022-09-08 04:43:52 -07:00
Miss Islington (bot) 8a776d1d51
gh-95778: Correctly pre-check for int-to-str conversion (GH-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>
(cherry picked from commit b126196838)

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2022-09-04 09:45:02 -07:00
Gregory P. Smith f8b71da9aa
[3.11] gh-95778: CVE-2020-10735: Prevent DoS by very large int() (#96500)
Integer to and from text conversions via CPython's bignum `int` type is not safe against denial of service attacks due to malicious input. Very large input strings with hundred thousands of digits can consume several CPU seconds.

This PR comes fresh from a pile of work done in our private PSRT security response team repo.

This backports https://github.com/python/cpython/pull/96499 aka 511ca94520

Signed-off-by: Christian Heimes [Red Hat] <christian@python.org>
Tons-of-polishing-up-by: Gregory P. Smith [Google] <greg@krypto.org>
Reviews via the private PSRT repo via many others (see the NEWS entry in the PR).

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

I wrote up [a one pager for the release managers](https://docs.google.com/document/d/1KjuF_aXlzPUxTK4BMgezGJ2Pn7uevfX7g0_mvgHlL7Y/edit#).
2022-09-02 09:48:57 -07:00
Miss Islington (bot) 583591134c
gh-96455: update example in exception_handling_notes.txt to the 3.11RC bytecode (GH-96456)
(cherry picked from commit a91f25577c)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2022-09-01 06:45:09 -07:00
Miss Islington (bot) 27950d8f76
GH-96187: Prevent _PyCode_GetExtra to return garbage for negative indexes (GH-96188)
(cherry picked from commit 16ebae4cd4)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2022-08-23 04:02:19 -07:00
Miss Islington (bot) 3ea0beb359
gh-96046: Initialize ht_cached_keys in PyType_Ready() (GH-96047)
(cherry picked from commit 53e6a9a725)

Co-authored-by: Christian Heimes <christian@python.org>
2022-08-22 02:12:42 -07:00