Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
picnixz wants to merge27 commits intopython:main
base:main
Choose a base branch
Loading
frompicnixz:fix/overflow-in-frame-sizeof-126119
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
27 commits
Select commitHold shift + click to select a range
dbf3d61
fix overflow in frame's stacksizes
picnixzOct 29, 2024
a566469
blurb
picnixzOct 29, 2024
222de28
blurb v2
picnixzOct 29, 2024
303109b
fix more cases
picnixzOct 29, 2024
d743a3d
improve test coverage!
picnixzOct 29, 2024
6b34c22
improve test coverage!
picnixzOct 29, 2024
044d1a5
fix logic
picnixzOct 31, 2024
d6f3bc4
remove un-necessary assertion
picnixzOct 31, 2024
31f36de
skip a test on free-threaded builds to avoid crash
picnixzOct 31, 2024
b26dd72
fix tests on 32-bit platforms
picnixzOct 31, 2024
fe0b04e
fix casts
picnixzOct 31, 2024
1fe8e28
fix boundary conditions
picnixzOct 31, 2024
40d8b91
Merge remote-tracking branch 'upstream/main' into fix/overflow-in-fra…
picnixzOct 31, 2024
8c7ce9c
Update Lib/test/test_frame.py
picnixzNov 7, 2024
f8a0eef
Update Misc/NEWS.d/next/Core_and_Builtins/2024-10-29-11-47-19.gh-issu…
picnixzNov 7, 2024
3130f94
change co_stacksize upper limit
picnixzNov 8, 2024
91f95de
remove test that cannot overflow now
picnixzNov 8, 2024
c5d7596
fix tests
picnixzNov 8, 2024
a0b85d4
remove unused imports
picnixzNov 8, 2024
04abc46
update comment
picnixzNov 9, 2024
0187b72
remove assertions from `gen_sizeof` and `frame_sizeof`
picnixzNov 9, 2024
c9969a4
update test
picnixzNov 9, 2024
6c0e1a6
update test
picnixzNov 9, 2024
a498df9
Merge branch 'main' into fix/overflow-in-frame-sizeof-126119
picnixzFeb 23, 2025
6284de6
Merge branch 'main' into fix/overflow-in-frame-sizeof-126119
picnixzMay 11, 2025
fdb2e89
address review
picnixzMay 15, 2025
990a69c
Merge remote-tracking branch 'upstream/main' into fix/code/overflow-1…
picnixzJun 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
fix tests on 32-bit platforms
  • Loading branch information
@picnixz
picnixz committedOct 31, 2024
commitb26dd7240f14fd77301e9e103e6b91a34e4ff8a3
12 changes: 9 additions & 3 deletionsLib/test/test_frame.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
import copy
import operator
import platform
import re
import sys
import textwrap
Expand DownExpand Up@@ -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)
frame = _testcapi.frame_new(evil_code, globals(), locals())
message = re.escape("size exceeds INT_MAX")
self.assertRaisesRegex(OverflowError, message, frame.__sizeof__)

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):
Expand Down
12 changes: 8 additions & 4 deletionsLib/test/test_generators.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -288,10 +288,14 @@ def f(): yield

if support.Py_GIL_DISABLED:
self.skipTest("segmentation fault on free-threaded builds")
# the following crashes on free-threaded builds for now
evil_gi_func = types.FunctionType(evil, {})()
message = re.escape("size exceeds INT_MAX")
self.assertRaisesRegex(OverflowError, message, evil_gi.__sizeof__)
elif sys.maxsize == 2147483647: # 32-bit machine
with self.assertRaises(MemoryError):
evil_gi = types.FunctionType(evil, {})()
else:
# the following crashes on free-threaded builds for now
evil_gi = types.FunctionType(evil, {})()
message = re.escape("size exceeds INT_MAX")
self.assertRaisesRegex(OverflowError, message, evil_gi.__sizeof__)


class ModifyUnderlyingIterableTest(unittest.TestCase):
Expand Down
4 changes: 3 additions & 1 deletionObjects/codeobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -439,13 +439,15 @@
/*
* The framesize = stacksize + nlocalsplus + FRAME_SPECIALS_SIZE is used
* as framesize * sizeof(PyObject *) and assumed to be < INT_MAX. Thus,
* we need to dynamically limit the value of stacksize.
* 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

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / build (arm64)

'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 450 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Windows / build (arm64)

'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 450 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Windows / build and test (x64)

'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 450 in Objects/codeobject.c

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / build and test (x64)

'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
if (con->stacksize >= max_stacksize) {
PyErr_SetString(PyExc_OverflowError, "code: co_stacksize is too large");
return -1;
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp