diff options
author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-03-31 13:13:05 +0000 |
---|---|---|
committer | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> | 2009-03-31 13:13:05 +0000 |
commit | 9d2ee5ded2ffd7e533776936ac3b34dbb782a847 (patch) | |
tree | 7ca4669f2c152d2be0f7f2811d702f67e443b299 | |
parent | b2898e0acb7c40c8e77f0210d564eefa4779f24a (diff) | |
download | cpython-git-9d2ee5ded2ffd7e533776936ac3b34dbb782a847.tar.gz |
Issue #5387: Fixed mmap.move crash by integer overflow.
-rw-r--r-- | Lib/test/test_mmap.py | 17 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Modules/mmapmodule.c | 6 |
3 files changed, 21 insertions, 4 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 2dd76ad9ff..b8998ea13d 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -339,6 +339,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) @@ -199,6 +199,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. diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 95dcfbe630..d191c1e6fb 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -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; |