mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Issue #14888: Fix misbehaviour of the _md5 module when called on data larger than 2**32 bytes.
This commit is contained in:
parent
d68ffdb45a
commit
cd8799f077
2 changed files with 17 additions and 3 deletions
|
@ -64,6 +64,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #14888: Fix misbehaviour of the _md5 module when called on data
|
||||||
|
larger than 2**32 bytes.
|
||||||
|
|
||||||
- Issue #14875: Use float('inf') instead of float('1e66666') in the json module.
|
- Issue #14875: Use float('inf') instead of float('1e66666') in the json module.
|
||||||
|
|
||||||
- Issue #14572: Prevent build failures with pre-3.5.0 versions of
|
- Issue #14572: Prevent build failures with pre-3.5.0 versions of
|
||||||
|
|
|
@ -262,6 +262,8 @@ MD5_new(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
md5object *md5p;
|
md5object *md5p;
|
||||||
Py_buffer view = { 0 };
|
Py_buffer view = { 0 };
|
||||||
|
Py_ssize_t n;
|
||||||
|
unsigned char *buf;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "|s*:new", &view))
|
if (!PyArg_ParseTuple(args, "|s*:new", &view))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -271,9 +273,18 @@ MD5_new(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view.len > 0) {
|
n = view.len;
|
||||||
md5_append(&md5p->md5, (unsigned char*)view.buf,
|
buf = (unsigned char *) view.buf;
|
||||||
Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int));
|
while (n > 0) {
|
||||||
|
Py_ssize_t nbytes;
|
||||||
|
if (n > INT_MAX)
|
||||||
|
nbytes = INT_MAX;
|
||||||
|
else
|
||||||
|
nbytes = n;
|
||||||
|
md5_append(&md5p->md5, buf,
|
||||||
|
Py_SAFE_DOWNCAST(nbytes, Py_ssize_t, unsigned int));
|
||||||
|
buf += nbytes;
|
||||||
|
n -= nbytes;
|
||||||
}
|
}
|
||||||
PyBuffer_Release(&view);
|
PyBuffer_Release(&view);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue