| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
PyOS_double_to_string() now raises ValueError("precision too big") for
precisions above INT_MAX - 1024, matching what the format parsers already
do above INT_MAX. Buffer size computations in pystrtod.c and dtoa.c add a
few hundred to the precision using int / Py_ssize_t arithmetic and could
wrap for such values, leading to a crash or incorrect output.
Also harden _Py_dg_dtoa() and rv_alloc() so their size arithmetic stays in
range for any C caller.
…ording Make the PyOS_double_to_string() precision check symmetric so that C callers passing a huge negative precision cannot reach the remaining precision arithmetic either. Reword the NEWS entry: the limit applies to float and complex formatting regardless of presentation type or value.
Note the dtoa.c deviations in its header list, cross-reference the shared bound between dtoa.c and pystrtod.c, PEP 7 brace placement, and wrap a long test comment. No functional change.
|
Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11, 3.12, 3.13, 3.14, 3.15. |
Sorry, something went wrong.
|
GH-158476 is a backport of this pull request to the 3.15 branch. |
Sorry, something went wrong.
|
GH-158477 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
|
GH-158478 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
|
Sorry, @gpshead, I could not cleanly backport this to 3.10 due to a conflict. cherry_picker b7b4f3ecf2fce4451ee1a8e8c1b6e92dea60ce3d 3.10 |
Sorry, something went wrong.
|
GH-158479 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
|
GH-158480 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
|
GH-158482 is a backport of this pull request to the 3.10 branch. |
Sorry, something went wrong.
…) (#158478) gh-158446: Reject float format precision near INT_MAX (GH-158474) Formatting a float or complex with a precision within about 1000 of INT_MAX could crash or produce incorrect output. PyOS_double_to_string() now raises ValueError("precision too big") for such precisions, as the format string parsers already do for precisions above INT_MAX. The limit applies regardless of presentation type or value, so a few calls that previously succeeded (inf, nan, or 'g' with such a precision) now raise as well. (cherry picked from commit b7b4f3e) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
…) (#158476) gh-158446: Reject float format precision near INT_MAX (GH-158474) Formatting a float or complex with a precision within about 1000 of INT_MAX could crash or produce incorrect output. PyOS_double_to_string() now raises ValueError("precision too big") for such precisions, as the format string parsers already do for precisions above INT_MAX. The limit applies regardless of presentation type or value, so a few calls that previously succeeded (inf, nan, or 'g' with such a precision) now raise as well. (cherry picked from commit b7b4f3e) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
…) (#158477) gh-158446: Reject float format precision near INT_MAX (GH-158474) Formatting a float or complex with a precision within about 1000 of INT_MAX could crash or produce incorrect output. PyOS_double_to_string() now raises ValueError("precision too big") for such precisions, as the format string parsers already do for precisions above INT_MAX. The limit applies regardless of presentation type or value, so a few calls that previously succeeded (inf, nan, or 'g' with such a precision) now raise as well. (cherry picked from commit b7b4f3e) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
…) (#158479) * gh-158446: Reject float format precision near INT_MAX (GH-158474) Formatting a float or complex with a precision within about 1000 of INT_MAX could crash or produce incorrect output. PyOS_double_to_string() now raises ValueError("precision too big") for such precisions, as the format string parsers already do for precisions above INT_MAX. The limit applies regardless of presentation type or value, so a few calls that previously succeeded (inf, nan, or 'g' with such a precision) now raise as well. (cherry picked from commit b7b4f3e) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> * gh-158446: Fix the new test_format test on 3.12 test_format.py does not import import_module on this branch. Import INT_MAX from _testcapi directly, as the neighboring test does. --------- Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
…) (#158482) Formatting a float or complex with a precision within about 1000 of INT_MAX could crash or produce incorrect output. PyOS_double_to_string() now raises ValueError("precision too big") for such precisions, as the format string parsers already do for precisions above INT_MAX. The limit applies regardless of presentation type or value, so a few calls that previously succeeded (inf, nan, or 'g' with such a precision) now raise as well. (cherry picked from commit b7b4f3e)
…) (#158480) * gh-158446: Reject float format precision near INT_MAX (GH-158474) Formatting a float or complex with a precision within about 1000 of INT_MAX could crash or produce incorrect output. PyOS_double_to_string() now raises ValueError("precision too big") for such precisions, as the format string parsers already do for precisions above INT_MAX. The limit applies regardless of presentation type or value, so a few calls that previously succeeded (inf, nan, or 'g' with such a precision) now raise as well. (cherry picked from commit b7b4f3e) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> * gh-158446: Fix the new test_format test on 3.11 test_format.py does not import import_module on this branch. Import INT_MAX from _testcapi directly, as the neighboring test does. --------- Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
| Back | FazBrowse Home | New Git URL |
PyOS_double_to_string() now raises ValueError("precision too big") for precisions above INT_MAX - 1024, matching what the format parsers already do above INT_MAX. Buffer size computations in pystrtod.c and dtoa.c add a few hundred to the precision using int / Py_ssize_t arithmetic and could wrap for such values, leading to a crash or incorrect output.
Also harden _Py_dg_dtoa() and rv_alloc() so their size arithmetic stays in range for any C caller.
This was reviewed and approved via the PSRT in a report which we'll make public soon as security releases are about to be cut tomorrow.