[New-bugs-announce] [issue34912] Update overflow checks in resize_buffer
Windson Yang
report at bugs.python.org
Sat Oct 6 01:31:56 EDT 2018
New submission from Windson Yang <wiwindson at gmail.com>:
In [resize_buffer](https://github.com/python/cpython/blob/e42b705188271da108de42b55d9344642170aa2b/Modules/_io/stringio.c#L85)
/* For simplicity, stay in the range of the signed type. Anyway, Python
doesn't allow strings to be longer than this. */
if (size > PY_SSIZE_T_MAX)
goto overflow;
...
IMO, we should check the overflow with
if (size > PY_SSIZE_T_MAX/sizeof(Py_UCS4))
Or we can just delete this code because we will check later at [alloc_check](https://github.com/python/cpython/blob/e42b705188271da108de42b55d9344642170aa2b/Modules/_io/stringio.c#L107)
BTW, I found we only use PY_SIZE_MAX here in CPython, I wonder why we do not use PY_SSIZE_T_MAX instead?
----------
components: IO
messages: 327223
nosy: Windson Yang
priority: normal
severity: normal
status: open
title: Update overflow checks in resize_buffer
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34912>
_______________________________________
More information about the New-bugs-announce
mailing list