[New-bugs-announce] [issue44698] Undefined behaviour in Objects/complexobject.c's complex_pow

Thomas Wouters report at bugs.python.org
Wed Jul 21 11:06:49 EDT 2021


New submission from Thomas Wouters <thomas at python.org>:

Objects/complexobject.c's complex_pow uses undefined behaviour, by casting a float of unknown magnitude to a long:

    int_exponent = (long)exponent.real;

At Google we build with clang and -fsanitize=float-cast-overflow by default, which catches this particular kind of undefined behaviour. We didn't notice, however, because the only code we've come across that exercises this behaviour was a commented-out test in test_complex, which was uncommented in 3.8. Running the test, or just '1e19+1j ** 1e19', is enough to trigger the undefined behaviour. I'll prepare a PR to fix it.

----------
assignee: twouters
messages: 397947
nosy: gregory.p.smith, twouters
priority: normal
severity: normal
status: open
title: Undefined behaviour in Objects/complexobject.c's complex_pow
type: behavior
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44698>
_______________________________________


More information about the New-bugs-announce mailing list