6897 Commits

Author SHA1 Message Date
Miss Islington (bot)
42762bb098
[3.9] gh-120384: gh-120298: Fix array-out-of-bounds & use after free list (GH-121345) (GH-140834)
(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:41 +01:00
Serhiy Storchaka
8d35fd1b34
[3.9] gh-133767: Fix use-after-free in the unicode-escape decoder with an error handler (GH-129648) (GH-133944) (#134346)
* [3.9] gh-133767: Fix use-after-free in the unicode-escape decoder with an error handler (GH-129648) (GH-133944)

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)
(cherry picked from commit 8b528cacbbde60504f6ac62784d04889d285f18b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-06-02 17:58:01 +02:00
Serhiy Storchaka
4a79328195
[3.9] gh-99612: Fix PyUnicode_DecodeUTF8Stateful() for ASCII-only data (GH-99613) (GH-107224) (#107231)
Previously *consumed was not set in this case.
(cherry picked from commit f08e52ccb027f6f703302b8c1a82db9fd3934270).
(cherry picked from commit b8b3e6afc0a48c3cbb7c36d2f73e332edcd6058c)
2023-08-22 20:25:15 +02:00
Victor Stinner
41188134bd
[3.9] gh-95778: Mention sys.set_int_max_str_digits() in error message (#96874) (#96877)
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: Ned Deily <nad@python.org>
2022-10-04 10:05:45 -07:00
Miss Islington (bot)
f65f3a9daf
[3.9] gh-97616: list_resize() checks for integer overflow (GH-97617) (GH-97627)
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-10-04 10:01:10 -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
Jelle Zijlstra
f82b32410b
[3.9] gh-92112: Fix crash triggered by an evil custom mro() (GH-92113) (GH-92372)
(cherry picked from commit 85354ed78c0edb6d81a2bd53cabc85e547b8b26e)

Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
2022-05-16 18:47:35 +02:00
Dennis Sweeney
801f77119d
[3.9] gh-92311: Let frame_setlineno jump over listcomps (#92740) 2022-05-12 17:41:34 -04:00
Thaddeus1499
e48da72647
[3.9] Remove effbot urls (GH-26308). (#92162)
(cherry picked from commit e9f66aedf44ccc3be27975cfb070a44ce6a6bd13)

Co-authored-by: E-Paine <63801254+E-Paine@users.noreply.github.com>
2022-05-02 12:22:05 -06:00
Miss Islington (bot)
206f416bd0
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:59:40 -07:00
Oleg Iarygin
312e16fb7b
[3.9] gh-91118: Fix docstrings that do not honor --without-doc-strings (GH-31769) (#91664)
Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
(cherry picked from commit a573cb2fec664c645ab744658d7e941d72e1a398)
2022-04-19 12:58:34 -07:00
Miss Islington (bot)
edf1a77f23
gh-91421: Use constant value check during runtime (GH-91422) (GH-91493)
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:55 -07:00
Miss Islington (bot)
98d57737de
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:24:39 -07:00
Miss Islington (bot)
d04a21344a
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:49:40 -07:00
Miss Islington (bot)
f1a5e1b89a
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:55:12 -07:00
Victor Stinner
a549cd1fc5
bpo-46852: Rename float.__set_format__() to float.__setformat__() (GH-31558) (GH-31581)
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 16:13:34 +01:00
Miss Islington (bot)
8eb18d842c
[3.9] bpo-46732: fix __bool__ docstring (GH-31301) (GH-31474)
(cherry picked from commit 0a222db2bca63070f429c0e613707da1bdfaf0e0)


Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-02-21 09:18:55 -08:00
Dennis Sweeney
c31b8a97a8
bpo-46615: Don't crash when set operations mutate the sets (GH-31120) (GH-31312)
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)
2022-02-13 12:29:42 +02:00
Miss Islington (bot)
f1796f2947
bpo-46417: Fix race condition on setting type __bases__ (GH-30788) (GH-30790)
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:42 +01:00
Miss Islington (bot)
54feddae88
docs: correct outdated MappingProxyType docstrings (GH-30281)
The docstrings for MappingProxyType's keys(), values(), and items()
methods were never updated to reflect the changes that Python 3 brought
to these APIs, namely returning views rather than lists.
(cherry picked from commit 2d10fa9bc4cf83c5e5dd73decc9a138d6d247374)

Co-authored-by: Joshua Bronson <jabronson@gmail.com>
2022-01-19 13:57:30 -08:00
Miss Islington (bot)
2d4049da1f
bpo-46085: Fix iterator cache mechanism of OrderedDict. (GH-30290)
(cherry picked from commit fb44d0589615590b1e7895ba78a038e96b15a219)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
2021-12-29 21:29:19 -08:00
Miss Islington (bot)
f5287ecd59
bpo-45392: Update the docstring of the 'type' built-in (GH-29439) (GH-29453)
(cherry picked from commit 91275207296c39e495fe118019a757c4ddefede8)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
2021-11-06 21:17:59 +01:00
Miss Islington (bot)
1e29dce113
bpo-30570: Use Py_EnterRecursiveCall() in issubclass() (GH-29048) (GH-29178)
* Use Py_EnterRecursiveCall() in issubclass()

Reviewed-by: Gregory P. Smith <greg@krypto.org> [Google]
(cherry picked from commit 423fa1c1817abfa8c3d1bc308ddbbd8f28b69d68)

Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
2021-11-04 21:20:21 +01:00
Serhiy Storchaka
6848602806
bpo-45467: Fix IncrementalDecoder and StreamReader in the "raw-unicode-escape" codec (GH-28944) (GH-28953)
They support now splitting escape sequences between input chunks.

Add the third parameter "final" in codecs.raw_unicode_escape_decode().
It is True by default to match the former behavior.

(cherry picked from commit 39aa98346d5dd8ac591a7cafb467af21c53f1e5d)
2021-10-14 21:23:52 +03: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 c96d1546b11b4c282a7e21737cb1f5d16349656d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-10-14 20:03:29 +03:00
Christian Clauss
960e7b3ba1
[3.9] Fix typos in the Objects directory (GH-28766) (GH-28795)
(cherry picked from commit 5f401f10400123afa9171548c432ea3fc37c0736)

Automerge-Triggered-By: GH:JulienPalard
2021-10-07 07:09:41 -07:00
Dong-hee Na
660718dba5
[3.9] bpo-45385: Fix reference leak from descr_check (GH-28719) (GH-28780)
(cherry picked from commit e6ff4eba6da9b64aed235ba8d730b5645f71955c)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
2021-10-07 11:10:15 +09:00
Serhiy Storchaka
e9ce081ec7
[3.9] Remove trailing spaces (GH-28710) 2021-10-03 20:04:38 +03:00
Łukasz Langa
5482db5800
[3.9] [codemod] Fix non-matching bracket pairs (GH-28473) (GH-28512)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>.
(cherry picked from commit 8f943ca25732d548cf9f0b0393ba8d582fb93e29)

Co-authored-by: Mohamad Mansour <66031317+mohamadmansourX@users.noreply.github.com>
2021-09-22 17:32:04 +02:00
Miss Islington (bot)
2746045a37
bpo-45167: Fix deepcopying of GenericAlias (GH-28324) (GH-28368)
(cherry picked from commit 5dce51a8875d9639786741e962b3cb208596b096)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-09-15 21:31:14 +02:00
Miss Islington (bot)
fecd17fbcb
bpo-45030: Fix integer overflow in __reduce__ of the range iterator (GH-28000)
It happened with fast range iterator  when the calculated stop = start + step * len
was out of the C long range.
(cherry picked from commit 936f6a16b9ef85bd56b18a247b962801e954c30e)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-09-04 13:39:47 -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 b4b6342848ec0459182a992151099252434cc619)

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)
02437641d2
bpo-45018: Fix rangeiter_reduce in rangeobject.c (GH-27938) (GH-27991)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 94a3d2a6329ab7941e93ad2f5bcbb8af2b8b80d2)

Co-authored-by: chilaxan <chilaxan@gmail.com>
2021-08-27 12:52:07 +02:00
Miss Islington (bot)
7ef0673de4
bpo-44954: Fix wrong result in float.fromhex corner case (GH-27834) (GH-27855)
(cherry picked from commit 60b93d9e4922eeae25052bc15909d1f4152babde)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
2021-08-20 12:37:41 +01:00
Miss Islington (bot)
beb3a835da
bpo-44698: Restore complex pow behaviour for small integral exponents (GH-27772) (GH-27797)
(cherry picked from commit 4b9a2dcf19e5d13c3bc2afea2de1f65cd994c699)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
2021-08-17 18:38:39 +01:00
Miss Islington (bot)
15f0a45b28
bpo-33930: Fix segfault with deep recursion when cleaning method objects (GH-27678) (GH-27720)
(cherry picked from commit bfc2d5a5c4550ab3a2fadeb9459b4bd948ff61a2)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-08-11 10:32:24 +02:00
Irit Katriel
ede1dc416d
bpo-44872: use new trashcan macros in framobject.c (GH-27683) (GH-27691) 2021-08-10 09:55:39 +02:00
Miss Islington (bot)
12fc0d28fc
bpo-44707: Fix an undefined behavior of the null pointer arithmetic (GH-27292) (GH-27443)
(cherry picked from commit e5c8ddb1714fb51ab1defa24352c98e0f01205dc)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-07-29 14:05:43 +02:00
Miss Islington (bot)
c48720576d
bpo-44657: Fix instancemethod_call to use PyInstanceMethod_GET_FUNCTION (GH-27202)
(cherry picked from commit ddf8ae31a0f371eff2db14c7f7a45976b86d56ea)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
2021-07-28 06:33:03 -07:00
Miss Islington (bot)
85ac81499e
bpo-44698: Fix undefined behaviour in complex exponentiation. (GH-27278) (GH-27367)
(cherry picked from commit 1d582bbc969e05896addf97844ddf17ce9830e5e)

Co-authored-by: T. Wouters <thomas@python.org>
2021-07-26 21:30:11 +02:00
Miss Islington (bot)
0a08f22184
bpo-44720: Don't crash when calling weakref.proxy(not_an_iterator).__next__ (GH-27316) (#27325)
(cherry picked from commit 5370f0a82aaa4ba617070d5c71d2b18236096ac0)

Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
2021-07-24 11:45:40 +02:00
Miss Islington (bot)
298ee657ab
bpo-44184: Fix subtype_dealloc() for freed type (GH-26274)
Fix a crash at Python exit when a deallocator function removes the
last strong reference to a heap type.

Don't read type memory after calling basedealloc() since
basedealloc() can deallocate the type and free its memory.

_PyMem_IsPtrFreed() argument is now constant.
(cherry picked from commit 615069eb08494d089bf24e43547fbc482ed699b8)

Co-authored-by: Victor Stinner <vstinner@python.org>
2021-07-15 16:36:51 -07:00
Miss Islington (bot)
0b4704973d
bpo-44184: Apply GH-26274 to the non-GC-type branch of subtype_dealloc (GH-27165) (GH-27175)
The non-GC-type branch of subtype_dealloc is using the type of an object after freeing in the same unsafe way as GH-26274 fixes. (I believe the old news entry covers this change well enough.)

https://bugs.python.org/issue44184
(cherry picked from commit 074e7659f208051b6b973f7fdb654dd22b93aaa2)

Co-authored-by: T. Wouters <thomas@python.org>
2021-07-16 01:35:25 +02:00
Ken Jin
51a29c42f1
[3.9] bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias … (GH-27016) (GH-27028) 2021-07-05 17:22:43 +01:00
Pablo Galindo
fe847a6285
Revert "bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias … (GH-27016) (GH-27018)" (GH-27022)
This reverts commit 4684a34c8d2a2ffac7b779edb4ba57f043783478.
2021-07-04 20:26:34 +01:00
Miss Islington (bot)
4684a34c8d
bpo-44562: Remove invalid PyObject_GC_Del from error path of types.GenericAlias … (GH-27016) (GH-27018)
(cherry picked from commit d33943a6c368c2184e238019c63ac7a267da5594)

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>

Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
2021-07-04 18:55:43 +01:00
Miss Islington (bot)
f790bc8084
bpo-44523: Remove the pass-through for hash() in weakref proxy objects (GH-26950) (GH-26960)
(cherry picked from commit e2fea101fd5517f33371b04432842b971021c3bf)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-06-30 00:19:32 +01:00
Miss Islington (bot)
9ee8752162
Fix a potential reference-counting bug in long_pow (GH-26690) (#26702)
(cherry picked from commit 59242431991794064824cf2ab70886367613f29e)

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>

Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
2021-06-13 08:42:43 +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 9032cf5cb1e33c0349089cfb0f6bf11ed3c30e86)

Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
2021-05-21 16:59:39 +02:00
Miss Islington (bot)
925cb85e9e
bpo-44114: Fix dictkeys_reversed and dictvalues_reversed function signatures (GH-26062) (GH-26093)
These are passed and called as PyCFunction, however they are defined here without the (ignored) args parameter.

This works fine in some C compilers, but fails in webassembly or anything else that has strict function pointer call type checking.
(cherry picked from commit ab383eb6f03896b0ef6634ee3d776344fcb9e5b8)

Co-authored-by: Joe Marshall <joe.marshall@nottingham.ac.uk>

Co-authored-by: Joe Marshall <joe.marshall@nottingham.ac.uk>
2021-05-16 17:34:43 +03:00