Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ef2b36

Browse files
committed
disallow a negative idx parameter
1 parent 99b5afa commit 6ef2b36

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Modules/_json.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -930,10 +930,11 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
930930
PyObject *res;
931931
Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr);
932932
Py_ssize_t length = PyUnicode_GET_SIZE(pystr);
933-
if (idx < 0)
934-
/* Compatibility with Python version. */
935-
idx += length;
936-
if (idx < 0 || idx >= length) {
933+
if (idx < 0) {
934+
PyErr_SetString(PyExc_ValueError, "idx canont be negative");
935+
return NULL;
936+
}
937+
if (idx >= length) {
937938
PyErr_SetNone(PyExc_StopIteration);
938939
return NULL;
939940
}

0 commit comments

Comments
 (0)