[Python-checkins] cpython (merge 3.2 -> 3.3): merge 3.2

benjamin.peterson python-checkins at python.org
Mon Apr 14 04:32:24 CEST 2014


http://hg.python.org/cpython/rev/4f15bd1ab28f
changeset:   90237:4f15bd1ab28f
branch:      3.3
parent:      90160:b49d990aaa9d
parent:      90236:8130b8c06606
user:        Benjamin Peterson <benjamin at python.org>
date:        Sun Apr 13 22:28:16 2014 -0400
summary:
  merge 3.2

files:
  Lib/test/test_json/test_decode.py |  4 ++++
  Misc/ACKS                         |  1 +
  Misc/NEWS                         |  3 +++
  Modules/_json.c                   |  5 ++++-
  4 files changed, 12 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py
--- a/Lib/test/test_json/test_decode.py
+++ b/Lib/test/test_json/test_decode.py
@@ -70,5 +70,9 @@
         msg = 'escape'
         self.assertRaisesRegex(ValueError, msg, self.loads, s)
 
+    def test_negative_index(self):
+        d = self.json.JSONDecoder()
+        self.assertRaises(ValueError, d.raw_decode, 'a'*42, -50000)
+
 class TestPyDecode(TestDecode, PyTest): pass
 class TestCDecode(TestDecode, CTest): pass
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1313,6 +1313,7 @@
 Alex Volkov
 Martijn Vries
 Sjoerd de Vries
+Guido Vranken
 Niki W. Waibel
 Wojtek Walczak
 Charles Waldman
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@
 Library
 -------
 
+- Fix arbitrary memory access in JSONDecoder.raw_decode with a negative second
+  parameter. Bug reported by Guido Vranken.
+
 - Issue #20633: Replace relative import by absolute import.
 
 - Issue #21082: In os.makedirs, do not set the process-wide umask. Note this
diff --git a/Modules/_json.c b/Modules/_json.c
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -975,7 +975,10 @@
     kind = PyUnicode_KIND(pystr);
     length = PyUnicode_GET_LENGTH(pystr);
 
-    if (idx >= length) {
+    if (idx < 0)
+        /* Compatibility with Python version. */
+        idx += length;
+    if (idx < 0 || idx >= length) {
         PyErr_SetNone(PyExc_StopIteration);
         return NULL;
     }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list