Skip to content

Commit b704f7e

Browse files
committed
Moved the INT_MAX length check to the top of the string parser.
1 parent fd4161d commit b704f7e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎Parser/string_parser.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ _PyPegen_parsestr(Parser *p, int *bytesmode, int *rawmode, PyObject **result,
175175
return -1;
176176
}
177177

178+
if (len > INT_MAX) {
179+
PyErr_SetString(PyExc_OverflowError, "string to parse is too long");
180+
return -1;
181+
}
182+
178183
int quote = Py_CHARMASK(*s);
179184
int fmode = 0;
180185
*bytesmode = 0;
@@ -226,10 +231,6 @@ _PyPegen_parsestr(Parser *p, int *bytesmode, int *rawmode, PyObject **result,
226231
/* Skip the leading quote char. */
227232
s++;
228233
len--;
229-
if (len > INT_MAX) {
230-
PyErr_SetString(PyExc_OverflowError, "string to parse is too long");
231-
return -1;
232-
}
233234
if (s[--len] != quote) {
234235
/* Last quote char must match the first. */
235236
PyErr_BadInternalCall();

0 commit comments

Comments
 (0)