diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2012-01-13 21:53:25 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2012-01-13 21:53:25 (GMT) |
commit | dee76e627d1561d519b0eb0b179e226f0e1a343f (patch) | |
tree | b3a4528be82a2413d3399ac9ea279124db0ed7d1 | |
parent | 44765e58b08b5591d30f194871cb672909159e4d (diff) | |
download | cpython-dee76e627d1561d519b0eb0b179e226f0e1a343f.zip cpython-dee76e627d1561d519b0eb0b179e226f0e1a343f.tar.gz cpython-dee76e627d1561d519b0eb0b179e226f0e1a343f.tar.bz2 |
Issue #13774: json: Fix a SystemError when a bogus encoding is passed to
json.loads().
-rw-r--r-- | Lib/json/tests/test_unicode.py | 4 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/_json.c | 9 |
3 files changed, 15 insertions, 1 deletions
diff --git a/Lib/json/tests/test_unicode.py b/Lib/json/tests/test_unicode.py index 31cf389..e90f158 100644 --- a/Lib/json/tests/test_unicode.py +++ b/Lib/json/tests/test_unicode.py @@ -80,6 +80,10 @@ class TestUnicode(object): # Issue 10038. self.assertEqual(type(self.loads('"foo"')), unicode) + def test_bad_encoding(self): + self.assertRaises(UnicodeEncodeError, self.loads, '"a"', u"rat\xe9") + self.assertRaises(TypeError, self.loads, '"a"', 1) + class TestPyUnicode(TestUnicode, PyTest): pass class TestCUnicode(TestUnicode, CTest): pass @@ -374,6 +374,9 @@ Library Extension Modules ----------------- +- Issue #13774: json: Fix a SystemError when a bogus encoding is passed to + json.loads(). + - Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by Vilmos Nebehaj. diff --git a/Modules/_json.c b/Modules/_json.c index 6b321e5..434b83c 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1725,8 +1725,15 @@ scanner_init(PyObject *self, PyObject *args, PyObject *kwds) Py_DECREF(s->encoding); s->encoding = tmp; } - if (s->encoding == NULL || !PyString_Check(s->encoding)) + if (s->encoding == NULL) goto bail; + if (!PyString_Check(s->encoding)) { + PyErr_Format(PyExc_TypeError, + "encoding must be a string, not %.80s", + Py_TYPE(s->encoding)->tp_name); + goto bail; + } + /* All of these will fail "gracefully" so we don't need to verify them */ s->strict = PyObject_GetAttrString(ctx, "strict"); |