Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix null derefs, missing decrefs, and unchecked returns from bug report
  • Loading branch information
A0su committed Mar 26, 2026
commit 089c19b9268687355697d1c371a28867343f0ca1
1 change: 1 addition & 0 deletions Python/assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ assemble_emit_instr(struct assembler *a, instruction *instr)
int size = instr_size(instr);
if (a->a_offset + size >= len / (int)sizeof(_Py_CODEUNIT)) {
if (len > PY_SSIZE_T_MAX / 2) {
PyErr_NoMemory();
return ERROR;
}
RETURN_IF_ERROR(_PyBytes_Resize(&a->a_bytecode, len * 2));
Expand Down
18 changes: 13 additions & 5 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,8 @@ codegen_unwind_fblock_stack(compiler *c, location *ploc,
_PyCompile_PopFBlock(c, top->fb_type, top->fb_block);
RETURN_IF_ERROR(codegen_unwind_fblock(c, ploc, &copy, preserve_tos));
RETURN_IF_ERROR(codegen_unwind_fblock_stack(c, ploc, preserve_tos, loop));
_PyCompile_PushFBlock(c, copy.fb_loc, copy.fb_type, copy.fb_block,
copy.fb_exit, copy.fb_datum);
RETURN_IF_ERROR(_PyCompile_PushFBlock(c, copy.fb_loc, copy.fb_type, copy.fb_block,
copy.fb_exit, copy.fb_datum));
return SUCCESS;
}

Expand Down Expand Up @@ -715,10 +715,14 @@ codegen_setup_annotations_scope(compiler *c, location loc,

// if .format > VALUE_WITH_FAKE_GLOBALS: raise NotImplementedError
PyObject *value_with_fake_globals = PyLong_FromLong(_Py_ANNOTATE_FORMAT_VALUE_WITH_FAKE_GLOBALS);
if (value_with_fake_globals == NULL) {
return ERROR;
}

assert(!SYMTABLE_ENTRY(c)->ste_has_docstring);
_Py_DECLARE_STR(format, ".format");
ADDOP_I(c, loc, LOAD_FAST, 0);
ADDOP_LOAD_CONST(c, loc, value_with_fake_globals);
ADDOP_LOAD_CONST_NEW(c, loc, value_with_fake_globals); // macro handles decref of value_with_fake_globals
Comment thread
A0su marked this conversation as resolved.
Outdated
ADDOP_I(c, loc, COMPARE_OP, (Py_GT << 5) | compare_masks[Py_GT]);
NEW_JUMP_TARGET_LABEL(c, body);
ADDOP_JUMP(c, loc, POP_JUMP_IF_FALSE, body);
Expand Down Expand Up @@ -816,7 +820,7 @@ codegen_deferred_annotations_body(compiler *c, location loc,

VISIT(c, expr, st->v.AnnAssign.annotation);
ADDOP_I(c, LOC(st), COPY, 2);
ADDOP_LOAD_CONST_NEW(c, LOC(st), mangled);
ADDOP_LOAD_CONST_NEW(c, LOC(st), mangled); // macro handles decref of mangle
// stack now contains <annos> <name> <annos> <value>
ADDOP(c, loc, STORE_SUBSCR);
// stack now contains <annos>
Expand Down Expand Up @@ -3279,7 +3283,11 @@ codegen_nameop(compiler *c, location loc,
}

int scope = _PyST_GetScope(SYMTABLE_ENTRY(c), mangled);
RETURN_IF_ERROR(scope);
if (scope == -1) {
Py_DECREF(mangled);
return ERROR;
Comment thread
A0su marked this conversation as resolved.
Outdated
}

_PyCompile_optype optype;
Py_ssize_t arg = 0;
if (_PyCompile_ResolveNameop(c, mangled, scope, &optype, &arg) < 0) {
Expand Down
4 changes: 4 additions & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1100,18 +1100,22 @@ _PyCompile_TweakInlinedComprehensionScopes(compiler *c, location loc,
assert(orig == NULL || orig == Py_True || orig == Py_False);
if (orig != Py_True) {
if (PyDict_SetItem(c->u->u_metadata.u_fasthidden, k, Py_True) < 0) {
Py_XDECREF(orig);
Comment thread
A0su marked this conversation as resolved.
return ERROR;
}
if (state->fast_hidden == NULL) {
state->fast_hidden = PySet_New(NULL);
if (state->fast_hidden == NULL) {
Py_XDECREF(orig);
return ERROR;
}
}
if (PySet_Add(state->fast_hidden, k) < 0) {
Py_XDECREF(orig);
return ERROR;
}
}
Py_XDECREF(orig);
}
}
}
Expand Down