summaryrefslogtreecommitdiffstats
path: root/Modules/mmapmodule.c
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2012-09-09 23:23:05 (GMT)
committerJesus Cea <jcea@jcea.es>2012-09-09 23:23:05 (GMT)
commit1b3f3b03164fb4b273dd710899adf11b47480231 (patch)
treefccfe0ceaa332424a2c6756481584abd31bf72c1 /Modules/mmapmodule.c
parentb21d48dabf40b5adc64c8968322c5974b6f4e572 (diff)
parent941bfcc537a25077e2a73ddf8d8b3bfe288c81f4 (diff)
downloadcpython-1b3f3b03164fb4b273dd710899adf11b47480231.zip
cpython-1b3f3b03164fb4b273dd710899adf11b47480231.tar.gz
cpython-1b3f3b03164fb4b273dd710899adf11b47480231.tar.bz2
Closes #15676: mmap: add empty file check prior to offset check
Diffstat (limited to 'Modules/mmapmodule.c')
-rw-r--r--Modules/mmapmodule.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index f52dce5..0f22d49 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1163,6 +1163,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");