Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-40458: Increase reserved stack space to prevent overflow crash on Windows #19845

Merged
merged 5 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion Lib/test/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def test_raise_exception(self):
for exc, name in (
('EXCEPTION_ACCESS_VIOLATION', 'access violation'),
('EXCEPTION_INT_DIVIDE_BY_ZERO', 'int divide by zero'),
('EXCEPTION_STACK_OVERFLOW', 'stack overflow'),
('EXCEPTION_STACK_OVERFLOW', r'stack overflow(\s+\(.+\))?'),
):
self.check_windows_exception(f"""
import faulthandler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Increase reserved stack space to prevent overflow crash on Windows.
12 changes: 11 additions & 1 deletion Modules/faulthandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
const int fd = fatal_error.fd;
DWORD code = exc_info->ExceptionRecord->ExceptionCode;
DWORD flags = exc_info->ExceptionRecord->ExceptionFlags;
PyThreadState *tstate;

if (faulthandler_ignore_exception(code)) {
/* ignore the exception: call the next exception handler */
Expand All @@ -402,7 +403,16 @@ faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
case EXCEPTION_INT_DIVIDE_BY_ZERO: PUTS(fd, "int divide by zero"); break;
case EXCEPTION_INT_OVERFLOW: PUTS(fd, "integer overflow"); break;
case EXCEPTION_IN_PAGE_ERROR: PUTS(fd, "page error"); break;
case EXCEPTION_STACK_OVERFLOW: PUTS(fd, "stack overflow"); break;
case EXCEPTION_STACK_OVERFLOW:
PUTS(fd, "stack overflow");
/* call UncheckedGet directly to avoid setting exceptions */
tstate = _PyThreadState_UncheckedGet();
zooba marked this conversation as resolved.
Show resolved Hide resolved
if (tstate != NULL) {
PUTS(fd, " (recursion depth=");
_Py_DumpDecimal(fd, tstate->recursion_depth);
PUTS(fd, ")");
}
break;
default:
PUTS(fd, "code 0x");
_Py_DumpHexadecimal(fd, code, 8);
Expand Down
1 change: 1 addition & 0 deletions PCbuild/python_uwp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Link>
<AdditionalDependencies>windowsapp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<StackReserveSize>2000000</StackReserveSize>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration) != 'Debug'">
Expand Down
1 change: 1 addition & 0 deletions PCbuild/pythonw_uwp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Link>
<AdditionalDependencies>windowsapp.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Windows</SubSystem>
<StackReserveSize>2000000</StackReserveSize>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration) != 'Debug'">
Expand Down