summaryrefslogtreecommitdiffstats
path: root/Objects/codeobject.c
diff options
context:
space:
mode:
authorAmmar Askar <ammar@ammaraskar.com>2021-03-17 18:26:38 (GMT)
committerGitHub <noreply@github.com>2021-03-17 18:26:38 (GMT)
commitdb733761060be92915b5f5cba209dcaada88f94e (patch)
tree18126f96fc3e03302c1ff3b10df17df916e33768 /Objects/codeobject.c
parent1f0cde678406749524d11e852a16bf243cef5c5f (diff)
downloadcpython-db733761060be92915b5f5cba209dcaada88f94e.zip
cpython-db733761060be92915b5f5cba209dcaada88f94e.tar.gz
cpython-db733761060be92915b5f5cba209dcaada88f94e.tar.bz2
[3.9] bpo-43499: Restrict co_code to be under INT_MAX in codeobject (GH-20628) (GH-24896)
(cherry picked from commit 3b3b83c965447a8329b34cb4befe6e9908880ee5)
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r--Objects/codeobject.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 7376359..cb4fb68 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -166,6 +166,14 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
return NULL;
}
+ /* Make sure that code is indexable with an int, this is
+ a long running assumption in ceval.c and many parts of
+ the interpreter. */
+ if (PyBytes_GET_SIZE(code) > INT_MAX) {
+ PyErr_SetString(PyExc_OverflowError, "co_code larger than INT_MAX");
+ return NULL;
+ }
+
/* Check for any inner or outer closure references */
n_cellvars = PyTuple_GET_SIZE(cellvars);
if (!n_cellvars && !PyTuple_GET_SIZE(freevars)) {