[issue27507] bytearray.extend lacks overflow check when increasing buffer

Antti Haapala report at bugs.python.org
Sun Jul 17 05:17:35 EDT 2016


Antti Haapala added the comment:

Ah indeed, this is a bytearray and it is indeed possible to theoretically allocate PY_SSIZE_T_MAX bytes, if on an architecture that does segmented memory.

As for 

    if (addition > PY_SSIZE_T_MAX - len - 1) {

it is very clear to *us* but it is not quite self-documenting on why to do it this way to someone who doesn't know undefined behaviours in C (hint: next to no one knows, judging from the amount of complaints that the GCC "bug" received), instead of say

    if (INT_ADD_OVERFLOW(len, addition))

Where the INT_ADD_OVERFLOW would have a comment above explaining why it has to be done that way. But more discussion about it at https://bugs.python.org/issue1621

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27507>
_______________________________________


More information about the Python-bugs-list mailing list