Skip to content

Commit fdb2e89

Browse files
committed
address review
1 parent 6284de6 commit fdb2e89

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Lib/test/test_code.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,13 +1132,13 @@ def foo(a, b):
11321132

11331133
c = foo.__code__
11341134

1135-
co_nlocalsplus = len({*c.co_varnames, *c.co_cellvars, *c.co_freevars})
1136-
# anything below that limit is a valid co_stacksize
1137-
evil_stacksize = int(_testcapi.INT_MAX / 16 - co_nlocalsplus)
1135+
# The exact limit depends on co_nlocalsplus, so we do not hardcode it.
1136+
too_large_stacksize = _testcapi.INT_MAX // 16
1137+
ok_stacksize = too_large_stacksize // 2
11381138

11391139
with self.assertRaisesRegex(OverflowError, "stack size is too large"):
1140-
c.__replace__(co_stacksize=evil_stacksize)
1141-
c.__replace__(co_stacksize=evil_stacksize - 1)
1140+
c.__replace__(co_stacksize=too_large_stacksize)
1141+
c.__replace__(co_stacksize=ok_stacksize)
11421142

11431143

11441144
def isinterned(s):
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Fix a crash in DEBUG builds due to an overflow when the :attr:`co_stacksize
2-
<codeobject.co_stacksize>` field of a :ref:`code object <code-objects>` is
3-
set to an absurdly large integer.
1+
Fix a crash in DEBUG builds due to a lack of overflow checks when setting
2+
the :attr:`co_stacksize <codeobject.co_stacksize>` field of a :ref:`code
3+
object <code-objects>` via :meth:`~object.__replace__`.
44
Reported by Valery Fedorenko. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)