cpython/Doc/whatsnew
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
..
2.0.rst [3.9] [docs] Improve the markup of powers (GH-28598) (GH-28608) 2021-09-28 23:13:16 +02:00
2.1.rst bpo-35506: Remove redundant and incorrect links from keywords. (GH-11174) 2018-12-19 08:09:46 +02:00
2.2.rst bpo-35506: Remove redundant and incorrect links from keywords. (GH-11174) 2018-12-19 08:09:46 +02:00
2.3.rst bpo-35506: Remove redundant and incorrect links from keywords. (GH-11174) 2018-12-19 08:09:46 +02:00
2.4.rst bpo-33641: Convert RFC references into links. (GH-7103) 2018-05-31 07:39:00 +03:00
2.5.rst gh-87670: Add web.archive redirects from effbot (GH-92816) 2022-05-15 23:32:15 -07:00
2.6.rst Docs: FIX broken links. (GH-13491) 2019-05-25 20:02:24 +02:00
2.7.rst gh-87670: Add web.archive redirects from effbot (GH-92816) 2022-05-15 23:32:15 -07:00
3.0.rst bpo-35506: Remove redundant and incorrect links from keywords. (GH-11174) 2018-12-19 08:09:46 +02:00
3.1.rst [3.9] [docs] Improve the markup of powers (GH-28598) (GH-28608) 2021-09-28 23:13:16 +02:00
3.2.rst gh-87670: Add web.archive redirects from effbot (GH-92816) 2022-05-15 23:32:15 -07:00
3.3.rst [3.9] bpo-40204: Allow pre-Sphinx 3 syntax in the doc (GH-21844) (GH-21901) 2020-08-19 19:25:22 +02:00
3.4.rst bpo-38600: NULL -> `NULL`. (GH-17001) 2019-10-30 21:37:16 +02:00
3.5.rst [3.9] bpo-40204: Allow pre-Sphinx 3 syntax in the doc (GH-21844) (GH-21901) 2020-08-19 19:25:22 +02:00
3.6.rst [3.9] bpo-42967: only use '&' as a query string separator (GH-24297) (#24528) 2021-02-15 10:03:31 -08:00
3.7.rst bpo-31415: importtime was made by Inada Naoki (GH-31875) 2022-03-14 14:30:15 -07:00
3.8.rst gh-83728: Add hmac.new default parameter deprecation (GH-91939) (GH-93546) 2022-06-06 19:10:56 +02:00
3.9.rst [3.9] gh-95778: CVE-2020-10735: Prevent DoS by very large int() (#96502) 2022-09-05 11:21:03 +02:00
changelog.rst Include additional changes to support blurbified NEWS (#3340) 2017-09-05 00:46:18 -07:00
index.rst Add 3.9 whatsnew file (GH-14040) 2019-06-12 23:31:45 -04:00