Commit 04a53853 authored by Benjamin Peterson's avatar Benjamin Peterson

fix possible overflow in encode_basestring_ascii (#23369)

parent 4ae4e7cb
...@@ -29,6 +29,9 @@ Core and Builtins ...@@ -29,6 +29,9 @@ Core and Builtins
Library Library
------- -------
- Issue #23369: Fixed possible integer overflow in
_json.encode_basestring_ascii.
- Issue #27568: Prevent HTTPoxy attack (CVE-2016-1000110). Ignore the - Issue #27568: Prevent HTTPoxy attack (CVE-2016-1000110). Ignore the
HTTP_PROXY variable when REQUEST_METHOD environment is set, which indicates HTTP_PROXY variable when REQUEST_METHOD environment is set, which indicates
that the script is in CGI mode. that the script is in CGI mode.
......
...@@ -211,6 +211,10 @@ ascii_escape_unicode(PyObject *pystr) ...@@ -211,6 +211,10 @@ ascii_escape_unicode(PyObject *pystr)
input_unicode = PyUnicode_AS_UNICODE(pystr); input_unicode = PyUnicode_AS_UNICODE(pystr);
/* One char input can be up to 6 chars output, estimate 4 of these */ /* One char input can be up to 6 chars output, estimate 4 of these */
if (input_chars > (PY_SSIZE_T_MAX - 2)/ MAX_EXPANSION) {
PyErr_SetString(PyExc_OverflowError, "string is too long to escape");
return NULL;
}
output_size = 2 + (MIN_EXPANSION * 4) + input_chars; output_size = 2 + (MIN_EXPANSION * 4) + input_chars;
max_output_size = 2 + (input_chars * MAX_EXPANSION); max_output_size = 2 + (input_chars * MAX_EXPANSION);
rval = PyString_FromStringAndSize(NULL, output_size); rval = PyString_FromStringAndSize(NULL, output_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment