Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
gh-126119: fix some crashes in code objects ifco_stacksize
is absurdly large#126122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
dbf3d61
a566469
222de28
303109b
d743a3d
6b34c22
044d1a5
d6f3bc4
31f36de
b26dd72
fe0b04e
1fe8e28
40d8b91
8c7ce9c
f8a0eef
3130f94
91f95de
c5d7596
a0b85d4
04abc46
0187b72
c9969a4
6c0e1a6
a498df9
6284de6
fdb2e89
990a69c
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import copy | ||
import operator | ||
import platform | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
import re | ||
import sys | ||
import textwrap | ||
@@ -236,9 +237,14 @@ def test_sizeof_overflow(self): | ||
evil_stacksize = int(_testcapi.INT_MAX / ps - fss - co_nlocalsplus) | ||
# an evil code with a valid (but very large) stack size | ||
evil_code = f.f_code.replace(co_stacksize=evil_stacksize - 1) | ||
if sys.maxsize == 2147483647: # 32-bit machine | ||
with self.assertRaises(MemoryError): | ||
frame = _testcapi.frame_new(evil_code, globals(), locals()) | ||
else: | ||
frame = _testcapi.frame_new(evil_code, globals(), locals()) | ||
message = re.escape("size exceeds INT_MAX") | ||
self.assertRaisesRegex(OverflowError, message, frame.__sizeof__) | ||
class ReprTest(unittest.TestCase): | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -439,13 +439,15 @@ | ||
/* | ||
* The framesize = stacksize + nlocalsplus + FRAME_SPECIALS_SIZE is used | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
* as framesize * sizeof(PyObject *) and assumed to be < INT_MAX. Thus, | ||
* we need to dynamically limit the value of stacksize. Note that this | ||
* usually prevents crashes due to assertions but a MemoryError may still | ||
* be triggered later. | ||
* | ||
* See https://github.com/python/cpython/issues/126119 for details. | ||
*/ | ||
int max_stacksize = (int)(INT_MAX / sizeof(PyObject *)) | ||
- FRAME_SPECIALS_SIZE | ||
- PyTuple_GET_SIZE(con->localsplusnames); | ||
Check warning on line 450 in Objects/codeobject.c
| ||
if (con->stacksize >= max_stacksize) { | ||
PyErr_SetString(PyExc_OverflowError, "code: co_stacksize is too large"); | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return -1; | ||
Uh oh!
There was an error while loading.Please reload this page.