@@ -236,6 +236,10 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict)
236236 if (chunks == NULL ) {
237237 goto bail ;
238238 }
239+ if (end < 0 || len <= end ) {
240+ PyErr_SetString (PyExc_ValueError , "end is out of bounds" );
241+ goto bail ;
242+ }
239243 while (1 ) {
240244 /* Find the end of the string or the next escape */
241245 Py_UNICODE c = 0 ;
@@ -246,7 +250,7 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict)
246250 break ;
247251 }
248252 else if (strict && c <= 0x1f ) {
249- raise_errmsg ("Invalid control character at" , pystr , begin );
253+ raise_errmsg ("Invalid control character at" , pystr , next );
250254 goto bail ;
251255 }
252256 }
@@ -401,6 +405,10 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict)
401405 if (chunks == NULL ) {
402406 goto bail ;
403407 }
408+ if (end < 0 || len <= end ) {
409+ PyErr_SetString (PyExc_ValueError , "end is out of bounds" );
410+ goto bail ;
411+ }
404412 while (1 ) {
405413 /* Find the end of the string or the next escape */
406414 Py_UNICODE c = 0 ;
@@ -411,7 +419,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict)
411419 break ;
412420 }
413421 else if (strict && c <= 0x1f ) {
414- raise_errmsg ("Invalid control character at" , pystr , begin );
422+ raise_errmsg ("Invalid control character at" , pystr , next );
415423 goto bail ;
416424 }
417425 }
0 commit comments