summaryrefslogtreecommitdiffstats
path: root/Modules/_json.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-02-01 22:59:49 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-02-01 22:59:49 (GMT)
commit3675cd9db1d7eda965df81357a11dd40e41090f7 (patch)
tree7736103010ac82c41b4a51eb5c4121dca198fb74 /Modules/_json.c
parent3a43d063213f221436ec00afca1d74b4a3b28c15 (diff)
parente3bfe19358f9d6747676fcdb9af415972d276671 (diff)
downloadcpython-3675cd9db1d7eda965df81357a11dd40e41090f7.zip
cpython-3675cd9db1d7eda965df81357a11dd40e41090f7.tar.gz
cpython-3675cd9db1d7eda965df81357a11dd40e41090f7.tar.bz2
merge 3.3 (#23369)
Diffstat (limited to 'Modules/_json.c')
-rw-r--r--Modules/_json.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/Modules/_json.c b/Modules/_json.c
index 1580ee6..f523aab 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -182,17 +182,24 @@ ascii_escape_unicode(PyObject *pystr)
/* Compute the output size */
for (i = 0, output_size = 2; i < input_chars; i++) {
Py_UCS4 c = PyUnicode_READ(kind, input, i);
- if (S_CHAR(c))
- output_size++;
+ Py_ssize_t d;
+ if (S_CHAR(c)) {
+ d = 1;
+ }
else {
switch(c) {
case '\\': case '"': case '\b': case '\f':
case '\n': case '\r': case '\t':
- output_size += 2; break;
+ d = 2; break;
default:
- output_size += c >= 0x10000 ? 12 : 6;
+ d = c >= 0x10000 ? 12 : 6;
}
}
+ if (output_size > PY_SSIZE_T_MAX - d) {
+ PyErr_SetString(PyExc_OverflowError, "string is too long to escape");
+ return NULL;
+ }
+ output_size += d;
}
rval = PyUnicode_New(output_size, 127);