diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-05-21 13:28:24 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-05-21 15:16:56 +0300 |
commit | 9cef9f5951eabaf010fc0b8d08b2d6e0c7dcf526 (patch) | |
tree | b3ac0bbc5f8433a1edfa6ec4a6944d69d7167d62 /simplejson/_speedups.c | |
parent | e84076f2cac4dd3cc98ed947316928cb5ba7c9b2 (diff) | |
download | simplejson-9cef9f5951eabaf010fc0b8d08b2d6e0c7dcf526.tar.gz |
Fix a crash wish unencodable encoding in the encoder.unencodable-encoder-encoding
JSONEncoder.encode() crashed in Python 3 when encoded bytes keys if the
encoding was not encodable to utf-8 (contained surrogates).
Diffstat (limited to 'simplejson/_speedups.c')
-rw-r--r-- | simplejson/_speedups.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c index d61f270..a9a05e3 100644 --- a/simplejson/_speedups.c +++ b/simplejson/_speedups.c @@ -642,10 +642,13 @@ encoder_stringify_key(PyEncoderObject *s, PyObject *key) } else if (PyString_Check(key)) { #if PY_MAJOR_VERSION >= 3 + const char *encoding = JSON_ASCII_AS_STRING(s->encoding); + if (encoding == NULL) + return NULL; return PyUnicode_Decode( PyString_AS_STRING(key), PyString_GET_SIZE(key), - JSON_ASCII_AS_STRING(s->encoding), + encoding, NULL); #else /* PY_MAJOR_VERSION >= 3 */ Py_INCREF(key); @@ -2599,6 +2602,8 @@ encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds) s->encoding = JSON_ParseEncoding(encoding); if (s->encoding == NULL) goto bail; + if (JSON_ASCII_AS_STRING(s->encoding) == NULL) + goto bail; Py_INCREF(indent); s->indent = indent; Py_INCREF(key_separator); |