Skip to content

Commit cf74e75

Browse files
committed
disallow a negative idx parameter
1 parent 66a3168 commit cf74e75

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Modules/_json.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,11 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
902902
PyObject *res;
903903
Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr);
904904
Py_ssize_t length = PyUnicode_GET_SIZE(pystr);
905-
if (idx < 0)
906-
/* Compatibility with Python version. */
907-
idx += length;
908-
if (idx < 0 || idx >= length) {
905+
if (idx < 0) {
906+
PyErr_SetString(PyExc_ValueError, "idx canont be negative");
907+
return NULL;
908+
}
909+
if (idx >= length) {
909910
PyErr_SetNone(PyExc_StopIteration);
910911
return NULL;
911912
}

0 commit comments

Comments
 (0)