Skip to content

Commit fda09a8

Browse files
author
benjamin.peterson
committed
check for error conditions in _json #3623
git-svn-id: http://svn.python.org/projects/python/trunk@66932 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 24ae1b0 commit fda09a8

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

Lib/json/tests/test_scanstring.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import decimal
33
from unittest import TestCase
44

5+
import json
56
import json.decoder
67

78
class TestScanString(TestCase):
@@ -100,3 +101,9 @@ def _test_scanstring(self, scanstring):
100101
self.assertEquals(
101102
scanstring('["Bad value", truth]', 2, None, True),
102103
(u'Bad value', 12))
104+
105+
def test_issue3623(self):
106+
self.assertRaises(ValueError, json.decoder.scanstring, b"xxx", 1,
107+
"xxx")
108+
self.assertRaises(UnicodeDecodeError,
109+
json.encoder.encode_basestring_ascii, b"xx\xff")

Modules/_json.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,13 @@ raise_errmsg(char *msg, PyObject *s, Py_ssize_t end)
179179
errmsg_fn = PyObject_GetAttrString(decoder, "errmsg");
180180
if (errmsg_fn == NULL)
181181
return;
182-
Py_XDECREF(decoder);
182+
Py_DECREF(decoder);
183183
}
184184
pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end);
185-
PyErr_SetObject(PyExc_ValueError, pymsg);
186-
Py_DECREF(pymsg);
185+
if (pymsg) {
186+
PyErr_SetObject(PyExc_ValueError, pymsg);
187+
Py_DECREF(pymsg);
188+
}
187189
/*
188190
189191
def linecol(doc, pos):

0 commit comments

Comments
 (0)