Closes #15676: mmap: add empty file check prior to offset check
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 @@
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");