#15676: mmap: add empty file check prior to offset check <- Previous patch was incomplete

This commit is contained in:
Jesus Cea 2012-09-10 22:50:21 +02:00
commit 4886d5b338
2 changed files with 10 additions and 5 deletions

View file

@ -491,11 +491,11 @@ class MmapTests(unittest.TestCase):
def test_empty_file (self):
f = open (TESTFN, 'w+b')
f.close()
f = open(TESTFN, "rb")
with open(TESTFN, "rb") as f :
self.assertRaisesRegex(ValueError,
"cannot mmap an empty file",
mmap.mmap, f.fileno(), 0, access=mmap.ACCESS_READ)
f.close()
mmap.mmap, f.fileno(), 0,
access=mmap.ACCESS_READ)
def test_offset (self):
f = open (TESTFN, 'w+b')

View file

@ -1364,6 +1364,11 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
}
size = (((PY_LONG_LONG) high) << 32) + low;
if (size == 0) {
PyErr_SetString(PyExc_ValueError,
"cannot mmap an empty file");
return NULL;
}
if (offset >= size) {
PyErr_SetString(PyExc_ValueError,
"mmap offset is greater than file size");