You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2016-09-27.06:55:49.693>created_at=<Date2016-09-27.06:54:57.874>labels= ['type-security']
title='Memory corruption due to size expansion (overflow) in _json.encode_basestring_ascii on 32 bit Python 2.7.12'updated_at=<Date2016-09-27.06:55:49.692>user='https://github.com/benjaminp'
/* One char input can be up to 6 chars output, estimate 4 of these */
output_size = 2 + (MIN_EXPANSION * 4) + input_chars;
- max_output_size = 2 + (input_chars * MAX_EXPANSION);+ if (input_chars > (PY_SSIZE_T_MAX / MAX_EXPANSION) ) {+ PyErr_SetString(PyExc_ValueError, "Size of escaped string
exceeds upper boundary");
+ return NULL;+ }+ max_output_size = (input_chars * MAX_EXPANSION);+ if ( max_output_size > (PY_SSIZE_T_MAX - 2)) {+ PyErr_SetString(PyExc_ValueError, "Size of escaped string
exceeds upper boundary");
+ return NULL;+ }+ max_output_size += 2;
rval = PyString_FromStringAndSize(NULL, output_size);
if (rval == NULL) {
return NULL;
But you still have to take account these things:
/* This is an upper bound */if (new_output_size>max_output_size) {
new_output_size=max_output_size;
}
If this code within the if{} is reached then it merely truncates the
amount of memory that is actually required, thereby creating another
opportunity for overwrites?
And this:
Py_ssize_tnew_output_size=output_size*2;
might overflow, but since output_size is always positive (ie. in the
range [0..PY_SSIZE_T_MAX]), an overflow would result in a negative
value. That would subsequently be caught in _PyString_Resize():
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: