Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32d2ce3

Browse files
committed
Issue #27581: Merge overflow fix from 3.5
2 parents c665dfd + e8db861 commit 32d2ce3

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Core and Builtins
1313
- Issue #27507: Add integer overflow check in bytearray.extend(). Patch by
1414
Xiang Zhang.
1515

16+
- Issue #27581: Don't rely on wrapping for overflow check in
17+
PySequence_Tuple(). Patch by Xiang Zhang.
18+
1619
- Issue #27419: Standard __import__() no longer look up "__import__" in globals
1720
or builtins for importing submodules or "from import". Fixed a crash if
1821
raise a warning about unabling to resolve package from __spec__ or

Objects/abstract.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,21 +1747,22 @@ PySequence_Tuple(PyObject *v)
17471747
break;
17481748
}
17491749
if (j >= n) {
1750-
Py_ssize_t oldn = n;
1750+
size_t newn = (size_t)n;
17511751
/* The over-allocation strategy can grow a bit faster
17521752
than for lists because unlike lists the
17531753
over-allocation isn't permanent -- we reclaim
17541754
the excess before the end of this routine.
17551755
So, grow by ten and then add 25%.
17561756
*/
1757-
n += 10;
1758-
n += n >> 2;
1759-
if (n < oldn) {
1757+
newn += 10u;
1758+
newn += newn >> 2;
1759+
if (newn > PY_SSIZE_T_MAX) {
17601760
/* Check for overflow */
17611761
PyErr_NoMemory();
17621762
Py_DECREF(item);
17631763
goto Fail;
17641764
}
1765+
n = (Py_ssize_t)newn;
17651766
if (_PyTuple_Resize(&result, n) != 0) {
17661767
Py_DECREF(item);
17671768
goto Fail;

0 commit comments

Comments
 (0)