mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
SF bug # 585792, Invalid mmap crashes Python interpreter
Raise ValueError if user passes a size to mmap which is larger than the file.
This commit is contained in:
parent
7165af23e6
commit
b567392bbf
4 changed files with 30 additions and 1 deletions
|
@ -850,6 +850,9 @@ _GetMapSize(PyObject *o)
|
|||
static PyObject *
|
||||
new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
|
||||
{
|
||||
#ifdef HAVE_FSTAT
|
||||
struct stat st;
|
||||
#endif
|
||||
mmap_object *m_obj;
|
||||
PyObject *map_size_obj = NULL;
|
||||
int map_size;
|
||||
|
@ -890,7 +893,14 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
|
|||
return PyErr_Format(PyExc_ValueError,
|
||||
"mmap invalid access parameter.");
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_FSTAT
|
||||
if (fstat(fd, &st) == 0 && (size_t)map_size > st.st_size) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"mmap length is greater than file size");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
m_obj = PyObject_New (mmap_object, &mmap_object_type);
|
||||
if (m_obj == NULL) {return NULL;}
|
||||
m_obj->size = (size_t) map_size;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue