summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Python/flowgraph.c
diff options
context:
space:
mode:
authorYDBot <[email protected]>2026-07-01 16:23:57 +0000
committerYDBot <[email protected]>2026-07-01 16:23:57 +0000
commite9b445a7f111ee5ba5c58672d767833df25ba262 (patch)
tree1b8bdb84d3fd994ff3ac60e36c30f93fbfce1243 /contrib/tools/python3/Python/flowgraph.c
parent1cfcce4de55cd075cfba845abf02c1554f141e01 (diff)
parentc98b5dbfe575ba628d7c3427854e7bd26030eb2c (diff)
Merge pull request #44637 from ydb-platform/merge-rightlib-260626-1120
Diffstat (limited to 'contrib/tools/python3/Python/flowgraph.c')
-rw-r--r--contrib/tools/python3/Python/flowgraph.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/contrib/tools/python3/Python/flowgraph.c b/contrib/tools/python3/Python/flowgraph.c
index ecf510842ea..baba1f75b9c 100644
--- a/contrib/tools/python3/Python/flowgraph.c
+++ b/contrib/tools/python3/Python/flowgraph.c
@@ -1244,6 +1244,14 @@ get_const_value(int opcode, int oparg, PyObject *co_consts)
PyObject *constant = NULL;
assert(OPCODE_HAS_CONST(opcode));
if (opcode == LOAD_CONST) {
+ assert(PyList_Check(co_consts));
+ Py_ssize_t n = PyList_GET_SIZE(co_consts);
+ if (oparg < 0 || oparg >= n) {
+ PyErr_Format(PyExc_ValueError,
+ "LOAD_CONST index %d is out of range for consts (len=%zd)",
+ oparg, n);
+ return NULL;
+ }
constant = PyList_GET_ITEM(co_consts, oparg);
}
@@ -2032,6 +2040,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
if (index_map == NULL) {
+ PyErr_NoMemory();
goto end;
}
for (Py_ssize_t i = 1; i < nconsts; i++) {
@@ -2045,6 +2054,12 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
for (int i = 0; i < b->b_iused; i++) {
if (OPCODE_HAS_CONST(b->b_instr[i].i_opcode)) {
int index = b->b_instr[i].i_oparg;
+ if (index < 0 || index >= nconsts) {
+ PyErr_Format(PyExc_ValueError,
+ "LOAD_CONST index %d is out of range for consts (len=%zd)",
+ index, nconsts);
+ goto end;
+ }
index_map[index] = index;
}
}
@@ -2083,6 +2098,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
/* adjust const indices in the bytecode */
reverse_index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
if (reverse_index_map == NULL) {
+ PyErr_NoMemory();
goto end;
}
for (Py_ssize_t i = 0; i < nconsts; i++) {