]> granicus.if.org Git - python/commitdiff
Issue #5292: Fixed mmap crash on its boundary access m[len(m)].
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Tue, 17 Feb 2009 10:12:10 +0000 (10:12 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Tue, 17 Feb 2009 10:12:10 +0000 (10:12 +0000)
Lib/test/test_mmap.py
Misc/NEWS
Modules/mmapmodule.c

index 6fecaf565b295365b0cc5b1d778a5d52ccfc4f33..e1e59670c6c9cbee85cc4bb9e8e33c5f6c8c24ff 100644 (file)
@@ -41,6 +41,10 @@ class MmapTests(unittest.TestCase):
             self.assertEqual(m[0], '\0')
             self.assertEqual(m[0:3], '\0\0\0')
 
+            # Shouldn't crash on boundary (Issue #5292)
+            self.assertRaises(IndexError, m.__getitem__, len(m))
+            self.assertRaises(IndexError, m.__setitem__, len(m), '\0')
+
             # Modify the file's content
             m[0] = '3'
             m[PAGESIZE +3: PAGESIZE +3+3] = 'bar'
index 004e9f7f8946a2b9737555e838a7de2e69573891..3b3f9d83e5c202d5e2c69714e692ed934cfda549 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -159,6 +159,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #5292: Fixed mmap crash on its boundary access m[len(m)].
+
 - Issue #2279: distutils.sdist.add_defaults now add files 
   from the package_data and the data_files metadata.
 
index a03957cf6fa402bbceb4781a54b2e5708ca1dde3..df2c058ec3fa2c11f69bc54bb8741240b59cb081 100644 (file)
@@ -731,7 +731,7 @@ mmap_subscript(mmap_object *self, PyObject *item)
                        return NULL;
                if (i < 0)
                        i += self->size;
-               if (i < 0 || (size_t)i > self->size) {
+               if (i < 0 || (size_t)i >= self->size) {
                        PyErr_SetString(PyExc_IndexError,
                                "mmap index out of range");
                        return NULL;
@@ -872,7 +872,7 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
                        return -1;
                if (i < 0)
                        i += self->size;
-               if (i < 0 || (size_t)i > self->size) {
+               if (i < 0 || (size_t)i >= self->size) {
                        PyErr_SetString(PyExc_IndexError,
                                "mmap index out of range");
                        return -1;