##// END OF EJS Templates
encoding: check overflow while calculating size of JSON escape buffer...
Yuya Nishihara -
r34032:e97be042 default
parent child Browse files
Show More
@@ -294,11 +294,21 b' static Py_ssize_t jsonescapelen(const ch'
294 return -1;
294 return -1;
295 }
295 }
296 esclen += jsonparanoidlentable[(unsigned char)c];
296 esclen += jsonparanoidlentable[(unsigned char)c];
297 if (esclen < 0) {
298 PyErr_SetString(PyExc_MemoryError,
299 "overflow in jsonescapelen");
300 return -1;
301 }
297 }
302 }
298 } else {
303 } else {
299 for (i = 0; i < len; i++) {
304 for (i = 0; i < len; i++) {
300 char c = buf[i];
305 char c = buf[i];
301 esclen += jsonlentable[(unsigned char)c];
306 esclen += jsonlentable[(unsigned char)c];
307 if (esclen < 0) {
308 PyErr_SetString(PyExc_MemoryError,
309 "overflow in jsonescapelen");
310 return -1;
311 }
302 }
312 }
303 }
313 }
304
314
@@ -366,7 +376,7 b' PyObject *jsonescapeu8fast(PyObject *sel'
366 origlen = PyBytes_GET_SIZE(origstr);
376 origlen = PyBytes_GET_SIZE(origstr);
367 esclen = jsonescapelen(origbuf, origlen, paranoid);
377 esclen = jsonescapelen(origbuf, origlen, paranoid);
368 if (esclen < 0)
378 if (esclen < 0)
369 return NULL; /* unsupported char found */
379 return NULL; /* unsupported char found or overflow */
370 if (origlen == esclen) {
380 if (origlen == esclen) {
371 Py_INCREF(origstr);
381 Py_INCREF(origstr);
372 return origstr;
382 return origstr;
General Comments 0
You need to be logged in to leave comments. Login now