summaryrefslogtreecommitdiff
path: root/Modules/mmapmodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-01-15 16:17:07 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2011-01-15 16:17:07 +0000
commit85f461550057e2a797cf7015c31f1a6d63553493 (patch)
treeb22a2158061dcbcb396d39f2ea4abb7f0633835a /Modules/mmapmodule.c
parentf5cf435bb52c8ba5ab6813bde70696fa3de98efa (diff)
downloadcpython-git-85f461550057e2a797cf7015c31f1a6d63553493.tar.gz
Issue #10916: mmap should not segfault when a file is mapped using 0 as
length and a non-zero offset, and an attempt to read past the end of file is made (IndexError is raised instead). Patch by Ross Lagerwall. Requested by Georg.
Diffstat (limited to 'Modules/mmapmodule.c')
-rw-r--r--Modules/mmapmodule.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 8a227527a5..ef026b260f 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1116,7 +1116,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
# endif
if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
if (map_size == 0) {
- map_size = st.st_size;
+ map_size = st.st_size - offset;
} else if ((size_t)offset + (size_t)map_size > st.st_size) {
PyErr_SetString(PyExc_ValueError,
"mmap length is greater than file size");