7163 Commits

Author SHA1 Message Date
Miss Islington (bot)
3eea546ed1
[3.10] gh-120384: gh-120298: Fix array-out-of-bounds & use after free list (GH-121345) (GH-140833)
(cherry picked from commit 8334a1b55c93068f5d243852029baa83377ff6c9)
(cherry picked from commit 0cd888b8d3a47428097571dddf5a0b5de37084e0)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2025-10-31 15:44:28 +01:00
Serhiy Storchaka
ab9893c406
[3.10] gh-133767: Fix use-after-free in the unicode-escape decoder with an error handler (GH-129648) (GH-133944) (GH-134345)
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 9f69a58623bd01349a18ba0c7a9cb1dad6a51e8e)
(cherry picked from commit 6279eb8c076d89d3739a6edb393e43c7929b429d)
(cherry picked from commit a75953b347716fff694aa59a7c7c2489fa50d1f5)
(cherry picked from commit 0c33e5baedf18ebcb04bc41dff7cfc614d5ea5fe)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-06-02 17:55:48 +02:00
Miss Islington (bot)
1c937e5887
[3.10] gh-99612: Fix PyUnicode_DecodeUTF8Stateful() for ASCII-only data (GH-99613) (GH-107224) (#107230)
Previously *consumed was not set in this case.

(cherry picked from commit b8b3e6afc0a48c3cbb7c36d2f73e332edcd6058c)
(cherry picked from commit f08e52ccb027f6f703302b8c1a82db9fd3934270)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-08-22 20:24:40 +02:00
Oleg Iarygin
fe36778968
[3.10] gh-101892: Fix SystemError when a callable iterator call exhausts the iterator (GH-101896) (#102422)
gh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (#101896)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
(cherry picked from commit 705487c6557c3d8866622b4d32528bf7fc2e4204)

Co-authored-by: Raj <51259329+workingpayload@users.noreply.github.com>
2023-03-04 20:56:12 +05:30
Miss Islington (bot)
4cc363611c
gh-101765: unicodeobject: use Py_XDECREF correctly (GH-102283)
(cherry picked from commit 8d0f09b1beafd95763a5da53acc58dac0bd63a53)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2023-02-26 15:09:43 -08:00
Jelle Zijlstra
6fa6c2a470
[3.10] gh-101765: Fix refcount issues in list and unicode pickling (GH-102265) (#102269)
(cherry picked from commit d71edbd1b7437706519a9786211597d95934331a)
2023-02-25 16:38:00 -08:00
Ionite
9f472f81bc
[3.10] gh-101765: Fix SystemError / segmentation fault in iter __reduce__ when internal access of builtins.__dict__ exhausts the iterator (GH-101769) (#102229)
(cherry picked from commit 54dfa14c5a94b893b67a4d9e9e403ff538ce9023)
2023-02-24 19:50:53 -08:00
Miss Islington (bot)
664141e34c
gh-101056: Fix memory leak in formatfloat() in bytesobject.c (GH-101057)
(cherry picked from commit b1a74a182d8762bda51838401ac92b6ebad9632a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2023-01-16 03:12:52 -08:00
Nikita Sobolev
b7b641a2ff
[3.10] GH-100942: Fix incorrect cast in property_copy(). (GH-100965). (#101009)
(cherry picked from commit 94fc7706b7bc3d57cdd6d15bf8e8c4499ae53a69)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
2023-01-15 12:38:59 +05:30
Miss Islington (bot)
64dae2efd5
gh-99845: _PyObject_DictPointer(): fix dictoffset cast (GH-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.
(cherry picked from commit 9707bf228e008485a3fbb63aa7ee28cf88014f91)

Co-authored-by: Victor Stinner <vstinner@python.org>
2022-12-01 05:32:15 -08:00
Serhiy Storchaka
9ca7b1561f
[3.10] gh-98852: Fix subscription of types.GenericAlias instances (GH-98920) (GH-98969)
Fix subscription of types.GenericAlias instances containing bare generic types:
for example tuple[A, T][int], where A is a generic type, and T is a type
variable.
2022-11-01 20:14:38 +02:00
Miss Islington (bot)
6a1d165c4c
obmalloc: Remove unused variable. (GH-98770)
(cherry picked from commit bded5edd9abf7ae6b2874916d70ec29ad209217c)

Co-authored-by: Benjamin Peterson <benjamin@python.org>
2022-10-27 09:33:44 -07:00
Miss Islington (bot)
e0e303abe4
[3.10] gh-97943: PyFunction_GetAnnotations should return a borrowed reference. (GH-97949) (GH-97989)
gh-97943: PyFunction_GetAnnotations should return a borrowed reference. (GH-97949)
(cherry picked from commit 6bfb0be80486c614cd60dce44c9fe7b3e6c76e3b)

Co-authored-by: larryhastings <larry@hastings.org>
2022-10-06 17:59:09 -07:00
Miss Islington (bot)
d108eeb678
gh-95196: Disable incorrect pickling of the C implemented classmethod descriptors (GH-96383)
(cherry picked from commit 77f0249308de76401bf4f3c6a057789c92f862d1)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-10-05 04:53:38 -07:00
Miss Islington (bot)
c6fcbb4928
gh-97591: In Exception.__setstate__() acquire strong references before calling tp_hash slot (GH-97700)
(cherry picked from commit d63943860974f232b5f027dc6535d25d1b4d8fc0)

Co-authored-by: Ofey Chan <ofey206@gmail.com>
2022-10-01 21:18:38 -07:00
Miss Islington (bot)
28f1435d94
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 a5f092f3c469b674b8d9ccbd4e4377230c9ac7cf)

Co-authored-by: Victor Stinner <vstinner@python.org>
2022-09-28 16:03:39 -07:00
Miss Islington (bot)
ce11f39de5
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 e841ffc915e82e5ea6e3b473205417d63494808d)

Co-authored-by: Victor Stinner <vstinner@python.org>
2022-09-16 11:30:05 -07:00
Miss Islington (bot)
19b94bc136
gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (GH-96353)
(cherry picked from commit b9634ac776c24bc4d4a57859d884a94cdfe16043)

Co-authored-by: philg314 <110174000+philg314@users.noreply.github.com>
2022-09-08 04:46:53 -07:00
Gregory P. Smith
eace09e63e
[3.10] gh-95778: Correctly pre-check for int-to-str conversion (GH-96537) (#96563)
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 b126196838bbaf5f4d35120e0e6bcde435b0b480)

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2022-09-04 09:54:56 -07:00
Gregory P. Smith
8f0fa4bd10
[3.10] gh-95778: CVE-2020-10735: Prevent DoS by very large int() (#96501)
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 511ca9452033ef95bc7d7fc404b8161068226002

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:51:49 -07:00
Pablo Galindo Salgado
a6c3f6d347
[3.10] GH-96187: Prevent _PyCode_GetExtra to return garbage for negative indexes (GH-96188). (#96210)
(cherry picked from commit 16ebae4cd4029205d932751f26c719c6cb8a6e92)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2022-08-23 15:58:25 +01:00
Kristján Valur Jónsson
d23ab79952
[3.10] GH--93592: Fix frame chain when throwing exceptions into coroutines (GH-95207) 2022-08-23 12:23:39 +01:00
Miss Islington (bot)
b4f968e094
gh-95605: Fix float(s) error message when s contains only whitespace (GH-95665) (GH-95859)
This PR fixes the error message from float(s) in the case where s contains only whitespace.
(cherry picked from commit 97e9cfa75a80b54a0630b7371f35e368a12749d1)

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2022-08-10 19:57:55 +01:00
Miss Islington (bot)
2d79804bb0
GH-91153: Handle mutating __index__ methods in bytearray item assignment (GH-94891)
(cherry picked from commit f36589510b8708fa224d799d5b328deab558aa4e)

Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
2022-07-19 10:04:47 -07:00
Neil Schemenauer
5d26f85521
[3.10] gh-94841: Ensure arena_map_get() is inlined in PyObject_Free() (GH-94842)
Need to define ALWAYS_INLINE macro for 3.10.

Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
2022-07-14 17:26:40 -07:00
Ken Jin
73b1d494a7
gh-92888: Fix memoryview bad __index__ use after free (GH-92946) (GH-93950)
(cherry picked from commit 11190c4ad0d3722b8d263758ac802985131a5462)

Co-authored-by: chilaxan <35645806+chilaxan@users.noreply.github.com>
Co-authored-by: Serhiy Storchaka <3659035+serhiy-storchaka@users.noreply.github.com>
2022-06-23 18:10:14 +08:00
Miss Islington (bot)
1b8aa7aafd
gh-93021: Fix __text_signature__ for __get__ (GH-93023) (GH-94086)
Because of the way wrap_descr_get is written, the second argument
to __get__ methods implemented through the wrapper is always
optional.
(cherry picked from commit 4e08fbcfdfa57ea94091aabdd09413708e3fb2bf)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-06-21 22:32:24 +02:00
Serhiy Storchaka
54250e7353
[3.10] gh-79512: Fixed names and __module__ value of weakref classes (GH-93719) (GH-94071)
Classes ReferenceType, ProxyType and CallableProxyType have now correct
atrtributes __module__, __name__ and __qualname__.
It makes them (types, not instances) pickleable.
(cherry picked from commit 8352e322e87ba39c71e578b65ad8ae156ca3e0c7)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-06-21 22:36:09 +03:00
Kumar Aditya
beba1020a9
GH-93990: fix refcounting bug in add_subclass in typeobject.c (GH-93989) (GH-93999)
(cherry picked from commit 726448ebe15cd78e180c29c9858cb6c10a581524)
2022-06-19 19:26:13 +08:00
Miss Islington (bot)
9204364e40
gh-92914: Round the allocated size for lists up to the even number (GH-92915) (GH-92942)
(cherry picked from commit 8a6af5a34642f5564220eb50d72caada8f17fc78)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-06-07 10:54:40 +02:00
Miss Islington (bot)
60adc4b92a
Fix missing word in sys.float_info docstring (GH-93489) (GH-93496)
(cherry picked from commit e12f34b6d8200508bd50cdc9c6c5637732ff56e7)

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2022-06-04 20:23:22 +01:00
Miss Islington (bot)
009aeb6bb6
bpo-39829: Fix __len__() is called twice in list() constructor (GH-31816)
(cherry picked from commit 2153daf0a02a598ed5df93f2f224c1ab2a2cca0d)

This patch fixes gh-87740 too.

Co-authored-by: Crowthebird <78076854+thatbirdguythatuknownot@users.noreply.github.com>
2022-05-18 13:16:58 +09:00
Dennis Sweeney
a24e676973
[3.10] gh-92311: Let frame_setlineno jump over listcomps (GH-92717) 2022-05-12 16:31:43 +01:00
Jelle Zijlstra
4674b315e5
[3.10] gh-92112: Fix crash triggered by an evil custom mro() (GH-92113) (#92370)
(cherry picked from commit 85354ed78c0edb6d81a2bd53cabc85e547b8b26e)

Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
2022-05-06 21:01:23 -07:00
Miss Islington (bot)
0eef443f01
Issues/88027: A potential double free in list_sort_impl (GH-92367)
merge_freemem(): set keys to NULL do it's harmless to call this again.
(cherry picked from commit 9652900969df77b1ac245595419431df19296af9)

Co-authored-by: Tim Peters <tim.peters@gmail.com>
2022-05-05 21:38:14 -07:00
Thaddeus1499
c8ab1633fc
[3.10] bpo-43504: Remove effbot urls (GH-26308) (#92161)
* [3.10] Remove effbot urls (GH-26308).
(cherry picked from commit e9f66aedf44ccc3be27975cfb070a44ce6a6bd13)

Co-authored-by: E-Paine <63801254+E-Paine@users.noreply.github.com>
2022-05-02 12:21:51 -06:00
Miss Islington (bot)
d985c8e2e0
bpo-36819: Fix crashes in built-in encoders with weird error handlers (GH-28593)
If the error handler returns position less or equal than the starting
position of non-encodable characters, most of built-in encoders didn't
properly re-size the output buffer. This led to out-of-bounds writes,
and segfaults.
(cherry picked from commit 18b07d773e09a2719e69aeaa925d5abb7ba0c068)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-05-02 02:58:41 -07:00
Oleg Iarygin
e7e8a9fa4f
[3.10] gh-91118: Fix docstrings that do not honor --without-doc-strings (GH-31769) (#91662)
Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit a573cb2fec664c645ab744658d7e941d72e1a398)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
2022-04-19 13:01:09 -07:00
Miss Islington (bot)
72114c06fd
gh-91421: Use constant value check during runtime (GH-91422) (GH-91492)
The left-hand side expression of the if-check can be converted to a
constant by the compiler, but the addition on the right-hand side is
performed during runtime.

Move the addition from the right-hand side to the left-hand side by
turning it into a subtraction there. Since the values are known to
be large enough to not turn negative, this is a safe operation.

Prevents a very unlikely integer overflow on 32 bit systems.

Fixes GH-91421.
(cherry picked from commit 0859368335d470b9ff33fc53ed9a85ec2654b278)

Co-authored-by: Tobias Stoeckmann <stoeckmann@users.noreply.github.com>
2022-04-13 18:38:37 -07:00
Miss Islington (bot)
69edc30d2b
Fix bad grammar and import docstring for split/rsplit (GH-32381) (GH-32416) 2022-04-08 12:06:19 -05:00
Christian Heimes
55d5c96c57
[3.10] bpo-47182: Fix crash by named unicode characters after interpreter reinitialization (GH-32212) (GH-32216)
Co-authored-by: Christian Heimes <christian@python.org>
2022-04-01 10:44:56 +02:00
Miss Islington (bot)
625f6704c0
bpo-14911: Corrected generator.throw() documentation (GH-32207)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
(cherry picked from commit 8be7c2bc5ad5e295f0f855bb31db412eef2c7c92)

Co-authored-by: Dave Goncalves <davegoncalves@gmail.com>
2022-03-31 07:23:04 -07:00
Miss Islington (bot)
1f2ec4cef1
bpo-46775: OSError should call winerror_to_errno unconditionally on Windows (GH-32179)
(cherry picked from commit d0c67ea0645b7ad37b867c167882a346a24de641)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
2022-03-30 18:48:31 -07:00
Miss Islington (bot)
cebdc32558
bpo-43721: Fix docstrings for property.getter/setter/deleter (GH-31046)
(cherry picked from commit e3d348a5252549708fd19338b675a2c23b60d677)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2022-03-14 16:51:55 -07:00
Pablo Galindo Salgado
3594ebca2c
[3.10] bpo-46940: Don't override existing AttributeError suggestion information (GH-31710) (GH-31724)
When an exception is created in a nested call to PyObject_GetAttr, any
external calls will override the context information of the
AttributeError that we have already placed in the most internal call.
This will cause the suggestions we create to nor work properly as the
attribute name and object that we will be using are the incorrect ones.

To avoid this, we need to check first if these attributes are already
set and bail out if that's the case..
(cherry picked from commit 3b3be05a164da43f201e35b6dafbc840993a4d18)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2022-03-07 13:18:36 +00:00
Victor Stinner
0848da19ce
bpo-46852: Rename float.__set_format__() to float.__setformat__() (GH-31558) (GH-31578)
Rename the private undocumented float.__set_format__() method to
float.__setformat__() to fix a typo introduced in Python 3.7. The
method is only used by test_float.

The change enables again test_float tests on the float format which
were previously skipped because of the typo.

The typo was introduced in Python 3.7 by bpo-20185
in commit b5c51d3dd95bbfde533655fb86ac0f96f771ba7b.

(cherry picked from commit 7d03c8be5af2f1559dbc35b775b3116dfd63cfb6)
2022-02-25 15:47:07 +01:00
Miss Islington (bot)
c596ecbf82
[3.10] bpo-46732: fix __bool__ docstring (GH-31301) (GH-31473)
(cherry picked from commit 0a222db2bca63070f429c0e613707da1bdfaf0e0)


Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-02-21 09:18:48 -08:00
Miss Islington (bot)
1f5fe9962f
bpo-46615: Don't crash when set operations mutate the sets (GH-31120)
Ensure strong references are acquired whenever using `set_next()`. Added randomized test cases for `__eq__` methods that sometimes mutate sets when called.
(cherry picked from commit 4a66615ba736f84eadf9456bfd5d32a94cccf117)

Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
2022-02-11 12:44:17 -08:00
Petr Viktorin
8b8673fe94
[3.10] bpo-46433: _PyType_GetModuleByDef: handle static types in MRO (GH-30696) (GH-31262)
(cherry picked from commit 0ef08530124c5ca13a9394f4ac18bee8e6c66409)
2022-02-11 12:25:25 +01:00
Miss Islington (bot)
acda9f3b90
bpo-46417: Fix race condition on setting type __bases__ (GH-30788) (GH-30789)
Fix a race condition on setting a type __bases__ attribute: the
internal function add_subclass() now gets the
PyTypeObject.tp_subclasses member after calling PyWeakref_NewRef()
which can trigger a garbage collection which can indirectly modify
PyTypeObject.tp_subclasses.
(cherry picked from commit f1c6ae3270913e095d24ae13ecf96f5a32c8c503)

Co-authored-by: Victor Stinner <vstinner@python.org>

Co-authored-by: Victor Stinner <vstinner@python.org>
2022-01-22 15:28:36 +01:00