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

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions 4 Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,7 @@ def test_validate_uop_unused_input(self):
"""
output = """
case OP: {
CHECK_STACK_BOUNDS(-1);
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
Expand All @@ -2132,6 +2133,7 @@ def test_validate_uop_unused_input(self):
"""
output = """
case OP: {
CHECK_STACK_BOUNDS(-1);
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
Expand All @@ -2153,6 +2155,7 @@ def test_validate_uop_unused_output(self):
case OP: {
JitOptRef foo;
foo = NULL;
CHECK_STACK_BOUNDS(1);
stack_pointer[0] = foo;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
Expand All @@ -2172,6 +2175,7 @@ def test_validate_uop_unused_output(self):
"""
output = """
case OP: {
CHECK_STACK_BOUNDS(1);
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check against abstract stack overflow in the JIT optimizer.
25 changes: 21 additions & 4 deletions 25 Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ incorrect_keys(PyObject *obj, uint32_t version)

#define CURRENT_FRAME_IS_INIT_SHIM() (ctx->frame->code == ((PyCodeObject *)&_Py_InitCleanup))

#define WITHIN_STACK_BOUNDS() \
(CURRENT_FRAME_IS_INIT_SHIM() || (STACK_LEVEL() >= 0 && STACK_LEVEL() <= STACK_SIZE()))


#define GETLOCAL(idx) ((ctx->frame->locals[idx]))

#define REPLACE_OP(INST, OP, ARG, OPERAND) \
Expand Down Expand Up @@ -192,6 +188,27 @@ incorrect_keys(PyObject *obj, uint32_t version)

#define JUMP_TO_LABEL(label) goto label;

static int
check_stack_bounds(JitOptContext *ctx, JitOptRef *stack_pointer, int offset, int opcode)
{
int stack_level = (int)(stack_pointer + (offset) - ctx->frame->stack);
int should_check = !CURRENT_FRAME_IS_INIT_SHIM() ||
(opcode == _RETURN_VALUE) ||
(opcode == _RETURN_GENERATOR) ||
(opcode == _YIELD_VALUE);
if (should_check && (stack_level < 0 || stack_level > STACK_SIZE())) {
ctx->contradiction = true;
ctx->done = true;
return 1;
}
return 0;
}

#define CHECK_STACK_BOUNDS(offset) \
if (check_stack_bounds(ctx, stack_pointer, offset, opcode)) { \
break; \
} \

static int
optimize_to_bool(
_PyUOpInstruction *this_instr,
Expand Down
Loading
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.