1
0
Fork 0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-05-29 14:56:08 +02:00

Fixed segfault on invalid unicode char on python 3

This commit is contained in:
Joakim Hamren 2014-10-28 23:09:15 +01:00
parent 4a2bfe9120
commit 7d28dc09ec
2 changed files with 10 additions and 0 deletions

View File

@ -835,6 +835,12 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t cbName)
case JT_UTF8:
{
value = enc->getStringValue(obj, &tc, &szlen);
if(!value)
{
SetError(obj, enc, "utf-8 encoding error");
return;
}
Buffer_Reserve(enc, RESERVE_STRING(szlen));
if (enc->errorMsg)
{

View File

@ -136,6 +136,10 @@ static void *PyUnicodeToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue, si
{
PyObject *obj = (PyObject *) _obj;
PyObject *newObj = PyUnicode_EncodeUTF8 (PyUnicode_AS_UNICODE(obj), PyUnicode_GET_SIZE(obj), NULL);
if(!newObj)
{
return NULL;
}
GET_TC(tc)->newObj = newObj;