summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2012-09-09 22:27:55 (GMT)
committerJesus Cea <jcea@jcea.es>2012-09-09 22:27:55 (GMT)
commit941bfcc537a25077e2a73ddf8d8b3bfe288c81f4 (patch)
treeaecc62becfac5c8a9592e021e60be2f3ec862620 /Modules
parent7330da42978ffcde525295ffc928ee3e0eedfb1b (diff)
downloadcpython-941bfcc537a25077e2a73ddf8d8b3bfe288c81f4.zip
cpython-941bfcc537a25077e2a73ddf8d8b3bfe288c81f4.tar.gz
cpython-941bfcc537a25077e2a73ddf8d8b3bfe288c81f4.tar.bz2
Closes #15676: mmap: add empty file check prior to offset check
Diffstat (limited to 'Modules')
-rw-r--r--Modules/mmapmodule.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index da9283b..e23613e 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1141,6 +1141,11 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
if (map_size == 0) {
off_t calc_size;
+ if (st.st_size == 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "cannot mmap an empty file");
+ return NULL;
+ }
if (offset >= st.st_size) {
PyErr_SetString(PyExc_ValueError,
"mmap offset is greater than file size");