mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Restrict co_code to be under INT_MAX in codeobject (GH-20628)
This commit is contained in:
		
							parent
							
								
									1642c0ef75
								
							
						
					
					
						commit
						3b3b83c965
					
				
					 2 changed files with 11 additions and 3 deletions
				
			
		|  | @ -166,6 +166,14 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, | ||||||
|         return NULL; |         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 */ |     /* Check for any inner or outer closure references */ | ||||||
|     n_cellvars = PyTuple_GET_SIZE(cellvars); |     n_cellvars = PyTuple_GET_SIZE(cellvars); | ||||||
|     if (!n_cellvars && !PyTuple_GET_SIZE(freevars)) { |     if (!n_cellvars && !PyTuple_GET_SIZE(freevars)) { | ||||||
|  |  | ||||||
|  | @ -397,9 +397,9 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     int len = Py_SAFE_DOWNCAST( |     /* PyCode_NewWithPosOnlyArgs limits co_code to be under INT_MAX so this
 | ||||||
|         PyBytes_GET_SIZE(f->f_code->co_code)/sizeof(_Py_CODEUNIT), |      * should never overflow. */ | ||||||
|         Py_ssize_t, int); |     int len = (int)(PyBytes_GET_SIZE(f->f_code->co_code) / sizeof(_Py_CODEUNIT)); | ||||||
|     int *lines = marklines(f->f_code, len); |     int *lines = marklines(f->f_code, len); | ||||||
|     if (lines == NULL) { |     if (lines == NULL) { | ||||||
|         return -1; |         return -1; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ammar Askar
						Ammar Askar