]> granicus.if.org Git - python/commitdiff
Merged revisions 70800 via svnmerge from
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Tue, 31 Mar 2009 13:22:01 +0000 (13:22 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Tue, 31 Mar 2009 13:22:01 +0000 (13:22 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r70800 | hirokazu.yamamoto | 2009-03-31 22:13:05 +0900 | 1 line

  Issue #5387: Fixed mmap.move crash by integer overflow.
........

Lib/test/test_mmap.py
Misc/NEWS
Modules/mmapmodule.c

index 31daa8df11d09708ab087a4831140b4fb167b85a..a73dfedaa3cdec57fa9620e8d68c01c8f203592e 100644 (file)
@@ -338,6 +338,23 @@ class MmapTests(unittest.TestCase):
         mf.close()
         f.close()
 
+        # more excessive test
+        data = "0123456789"
+        for dest in range(len(data)):
+            for src in range(len(data)):
+                for count in range(len(data) - max(dest, src)):
+                    expected = data[:dest] + data[src:src+count] + data[dest+count:]
+                    m = mmap.mmap(-1, len(data))
+                    m[:] = data
+                    m.move(dest, src, count)
+                    self.assertEqual(m[:], expected)
+                    m.close()
+
+        # should not crash
+        m = mmap.mmap(-1, 1)
+        self.assertRaises(ValueError, m.move, 1, 1, -1)
+        m.close()
+
     def test_anonymous(self):
         # anonymous mmap.mmap(-1, PAGE)
         m = mmap.mmap(-1, PAGESIZE)
index d49fc0d2e96da8f5991ad04efa1fb3b79bd7a8b7..2b3e3b8348af1f76bf8971107e89f59912a93405 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -92,6 +92,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #5387: Fixed mmap.move crash by integer overflow.
+
 - Issue #5261: Patch multiprocessing's semaphore.c to support context
   manager use: "with multiprocessing.Lock()" works now.
 
index 95dcfbe630564a9c52b2b24d85827a727ffcb91e..d191c1e6fb122ed47e6113834052508f06db3913 100644 (file)
@@ -612,10 +612,8 @@ mmap_move_method(mmap_object *self, PyObject *args)
                return NULL;
        } else {
                /* bounds check the values */
-               if (/* end of source after end of data?? */
-                       ((src+count) > self->size)
-                       /* dest will fit? */
-                       || (dest+count > self->size)) {
+               unsigned long pos = src > dest ? src : dest;
+               if (self->size >= pos && count > self->size - pos) {
                        PyErr_SetString(PyExc_ValueError,
                                        "source or destination out of range");
                        return NULL;