summaryrefslogtreecommitdiffstats
path: root/Modules/mmapmodule.c
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2012-09-09 22:22:39 (GMT)
committerJesus Cea <jcea@jcea.es>2012-09-09 22:22:39 (GMT)
commit8b54d6d73312186b4736cdf69a4e2e46ba15784c (patch)
tree82b6af0a0544635996bf5c899c6d58036816b1a8 /Modules/mmapmodule.c
parent10fc104fede2449468fb9488bb44a9663382b3a8 (diff)
downloadcpython-8b54d6d73312186b4736cdf69a4e2e46ba15784c.zip
cpython-8b54d6d73312186b4736cdf69a4e2e46ba15784c.tar.gz
cpython-8b54d6d73312186b4736cdf69a4e2e46ba15784c.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 a5027f5..8cf0e87 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1189,6 +1189,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");