File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ Core and Builtins
2424Library
2525-------
2626
27+ - Issue #24522: Fix possible integer overflow in json accelerator module.
28+
2729- Issue #24489: ensure a previously set C errno doesn't disturb cmath.polar().
2830
2931- Issue #24408: Fixed AttributeError in measure() and metrics() methods of
Original file line number Diff line number Diff line change @@ -249,17 +249,23 @@ escape_unicode(PyObject *pystr)
249249 /* Compute the output size */
250250 for (i = 0 , output_size = 2 ; i < input_chars ; i ++ ) {
251251 Py_UCS4 c = PyUnicode_READ (kind , input , i );
252+ Py_ssize_t d ;
252253 switch (c ) {
253254 case '\\' : case '"' : case '\b' : case '\f' :
254255 case '\n' : case '\r' : case '\t' :
255- output_size + = 2 ;
256+ d = 2 ;
256257 break ;
257258 default :
258259 if (c <= 0x1f )
259- output_size + = 6 ;
260+ d = 6 ;
260261 else
261- output_size ++ ;
262+ d = 1 ;
263+ }
264+ if (output_size > PY_SSIZE_T_MAX - d ) {
265+ PyErr_SetString (PyExc_OverflowError , "string is too long to escape" );
266+ return NULL ;
262267 }
268+ output_size += d ;
263269 }
264270
265271 rval = PyUnicode_New (output_size , maxchar );
You can’t perform that action at this time.
0 commit comments