mirror of
https://github.com/python/cpython.git
synced 2026-05-08 11:31:13 +00:00
[3.14] gh-148973: fix segfault on mismatch between consts size and oparg in compiler (GH-148974) (#148980)
gh-148973: fix segfault on mismatch between consts size and oparg in compiler (GH-148974)
(cherry picked from commit c650b51c32)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
parent
89f44ac422
commit
8acb98a1c2
5 changed files with 95 additions and 6 deletions
|
|
@ -1610,6 +1610,7 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
|
|||
{
|
||||
PyObject *res = NULL;
|
||||
PyObject *metadata = NULL;
|
||||
PyObject *consts_list = NULL;
|
||||
|
||||
if (!PyAST_Check(ast)) {
|
||||
PyErr_SetString(PyExc_TypeError, "expected an AST");
|
||||
|
|
@ -1664,12 +1665,23 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
|
|||
}
|
||||
|
||||
if (_PyInstructionSequence_ApplyLabelMap(_PyCompile_InstrSequence(c)) < 0) {
|
||||
return NULL;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
/* After AddReturnAtEnd: co_consts indices match the final instruction stream. */
|
||||
consts_list = consts_dict_keys_inorder(umd->u_consts);
|
||||
if (consts_list == NULL) {
|
||||
goto finally;
|
||||
}
|
||||
if (PyDict_SetItemString(metadata, "consts", consts_list) < 0) {
|
||||
goto finally;
|
||||
}
|
||||
|
||||
/* Allocate a copy of the instruction sequence on the heap */
|
||||
res = PyTuple_Pack(2, _PyCompile_InstrSequence(c), metadata);
|
||||
|
||||
finally:
|
||||
Py_XDECREF(consts_list);
|
||||
Py_XDECREF(metadata);
|
||||
_PyCompile_ExitScope(c);
|
||||
compiler_free(c);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue