From 1071d9d2fd99c18585fa630ea7f45b34a824278f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Thu, 25 Aug 2016 18:36:13 +0200
Subject: [PATCH] JSON add boundary check
---
Modules/_json.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/Modules/_json.c b/Modules/_json.c
index 4bc585d..fdbf3d9 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -979,7 +979,10 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
PyErr_SetString(PyExc_ValueError, "idx cannot be negative");
return NULL;
}
- if (idx >= length) {
+ if (idx < 0)
+ /* Compatibility with Python version. */
+ idx += length;
+ if (idx < 0 || idx >= length) {
PyErr_SetNone(PyExc_StopIteration);
return NULL;
}
--
2.9.0