File tree Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change 11import copy
22import operator
3+ import platform
34import re
45import sys
56import textwrap
@@ -236,9 +237,14 @@ def test_sizeof_overflow(self):
236237 evil_stacksize = int (_testcapi .INT_MAX / ps - fss - co_nlocalsplus )
237238 # an evil code with a valid (but very large) stack size
238239 evil_code = f .f_code .replace (co_stacksize = evil_stacksize - 1 )
239- frame = _testcapi .frame_new (evil_code , globals (), locals ())
240- message = re .escape ("size exceeds INT_MAX" )
241- self .assertRaisesRegex (OverflowError , message , frame .__sizeof__ )
240+
241+ if sys .maxsize == 2147483647 : # 32-bit machine
242+ with self .assertRaises (MemoryError ):
243+ frame = _testcapi .frame_new (evil_code , globals (), locals ())
244+ else :
245+ frame = _testcapi .frame_new (evil_code , globals (), locals ())
246+ message = re .escape ("size exceeds INT_MAX" )
247+ self .assertRaisesRegex (OverflowError , message , frame .__sizeof__ )
242248
243249
244250class ReprTest (unittest .TestCase ):
Original file line number Diff line number Diff line change @@ -288,10 +288,14 @@ def f(): yield
288288
289289 if support .Py_GIL_DISABLED :
290290 self .skipTest ("segmentation fault on free-threaded builds" )
291- # the following crashes on free-threaded builds for now
292- evil_gi_func = types .FunctionType (evil , {})()
293- message = re .escape ("size exceeds INT_MAX" )
294- self .assertRaisesRegex (OverflowError , message , evil_gi .__sizeof__ )
291+ elif sys .maxsize == 2147483647 : # 32-bit machine
292+ with self .assertRaises (MemoryError ):
293+ evil_gi = types .FunctionType (evil , {})()
294+ else :
295+ # the following crashes on free-threaded builds for now
296+ evil_gi = types .FunctionType (evil , {})()
297+ message = re .escape ("size exceeds INT_MAX" )
298+ self .assertRaisesRegex (OverflowError , message , evil_gi .__sizeof__ )
295299
296300
297301class ModifyUnderlyingIterableTest (unittest .TestCase ):
Original file line number Diff line number Diff line change @@ -439,7 +439,9 @@ _PyCode_Validate(struct _PyCodeConstructor *con)
439439 /*
440440 * The framesize = stacksize + nlocalsplus + FRAME_SPECIALS_SIZE is used
441441 * as framesize * sizeof(PyObject *) and assumed to be < INT_MAX. Thus,
442- * we need to dynamically limit the value of stacksize.
442+ * we need to dynamically limit the value of stacksize. Note that this
443+ * usually prevents crashes due to assertions but a MemoryError may still
444+ * be triggered later.
443445 *
444446 * See https://github.com/python/cpython/issues/126119 for details.
445447 */
You can’t perform that action at this time.
0 commit comments