-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
https://github.com/python/cpython/blob/main/Objects/complexobject.c#L150 _Py_c_pow()
contains:
at = atan2(a.imag, a.real);
phase = at*b.real;
if (b.imag != 0.0) {
len /= exp(at*b.imag);
An oss-fuzz pycompiler fuzzer identified a problem compiling the code " 9J**33J**3
" within the optimizer folding the constant by doing the math in place. We haven't been able to reproduce this ourselves - but code inspection reveals a potential problem:
C exp(x)
can return 0 in a couple of cases. Which would lead to the /= executing an undefined division by zero operation.
I believe the correct _Py_c_pow()
code should look something like:
if (b.imag != 0.0) {
double tmp_exp = exp(at*b.imag);
if (exp == 0.0 || errno == ERANGE) {
// Detected as OverflowError by our caller.
r.real = Py_HUGE_VAL;
r.imag = Py_HUGE_VAL;
return r;
}
len /= tmp_exp;
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error