X Tutup
The Wayback Machine - https://web.archive.org/web/20221214182611/https://github.com/python/cpython/pull/96504/commits
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.7] gh-95778: CVE-2020-10735: Prevent DoS by very large int() #96504

Merged
merged 23 commits into from Sep 6, 2022

Commits on Sep 2, 2022

  1. Backport CVE-2020-10735 to 3.7 from 3.8.

    This is based off of psrt/CVE-2020-10735-3.8backport branch at cd54fc3.
    gpshead committed Sep 2, 2022
  2. Add What's New entry.

    gpshead committed Sep 2, 2022
  3. Hack: Force CI run

    tiran authored and gpshead committed Sep 2, 2022
  4. Backport ctypes test_macholib fix from b29d0a5.

    This is required for the 3.7 tree to pass on modern macOS.
    gpshead committed Sep 2, 2022
  5. annotate test_bad_password @requires_zlib.

    I don't know why, but macOS in 3.7 CI is failing to build the zlib
    module these days so it's exposing this test that didn't have the
    proper `@requires_zlib` annotation.
    
    Getting it to build with zlib and other things that are now wrongly
    "missing" in the 3.7 CI setup would be nice, but probably involves
    invasive backporting of parts of
    python@b29d0a5
    by a macOS domain expert.
    
    Not worth it.
    gpshead committed Sep 2, 2022
  6. disable MachOTest.test_find unless macOS 11+ support is backported.

    This test also appears to require changes to
    Lib/ctypes/macholib/dyld.py to work in the existing macOS CI config.
    I'm just skipping it, backporting that would be a feature.
    Not going to happen in 3.7.
    
    There may be a way to configure macOS CI to use an older macOS and
    toolchain instead as an alternate option.  Someone else can figure
    that out if so.  This branch only lives for another 9 months per
    https://peps.python.org/pep-0537/
    gpshead committed Sep 2, 2022
  7. Move the whatsnew 3.7.14 text per review.

    Thanks Ned!
    gpshead committed Sep 2, 2022
  8. LOL at my typo

    gpshead committed Sep 2, 2022
  9. remove a line that prevents doctest error reporting.

    the 3.8 branch got rid of this line already.  it blocks seeing the
    actual error while testing a doc build!
    gpshead committed Sep 2, 2022
  10. Fix the docs build.

    gpshead committed Sep 2, 2022
  11. hexadecimal spelling =)

    gpshead committed Sep 2, 2022

Commits on Sep 4, 2022

  1. doc typo: limitation

    gpshead committed Sep 4, 2022
  2. remove unneeded doc note on float.as_integer_ratio

    Per mdickinson@'s comment on the main branch PR.
    gpshead committed Sep 4, 2022
  3. pythongh-95778: Correctly pre-check for int-to-str conversion (python…

    …#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: pythongh-95778 -->
    * Issue: pythongh-95778
    <!-- /gh-issue-number -->
    
    Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
    mdickinson and gpshead committed Sep 4, 2022
X Tutup