Issue #13774: json: Fix a SystemError when a bogus encoding is passed to
json.loads().
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 @@
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");