mirror of
https://github.com/python/cpython.git
synced 2025-12-02 07:37:25 +00:00
Issue #532631: Add paranoid check to avoid potential buffer overflow
on systems with sizeof(int) > 4.
This commit is contained in:
parent
2e648ecc7d
commit
174e909842
1 changed files with 10 additions and 1 deletions
|
|
@ -4344,6 +4344,15 @@ formatfloat(char *buf, size_t buflen, int flags,
|
||||||
}
|
}
|
||||||
if (prec < 0)
|
if (prec < 0)
|
||||||
prec = 6;
|
prec = 6;
|
||||||
|
/* make sure that the decimal representation of precision really does
|
||||||
|
need at most 10 digits: platforms with sizeof(int) == 8 exist! */
|
||||||
|
if (prec > 0x7fffffffL) {
|
||||||
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
|
"outrageously large precision "
|
||||||
|
"for formatted float");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == 'f' && fabs(x) >= 1e50)
|
if (type == 'f' && fabs(x) >= 1e50)
|
||||||
type = 'g';
|
type = 'g';
|
||||||
/* Worst case length calc to ensure no buffer overrun:
|
/* Worst case length calc to ensure no buffer overrun:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue