Index: Lib/test/test_mmap.py =================================================================== --- Lib/test/test_mmap.py (revision 70247) +++ Lib/test/test_mmap.py (working copy) @@ -338,6 +338,28 @@ 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 = list(data) + expected[dest:dest+count] = expected[src:src+count] + expected = "".join(expected) + 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) + try: + m.move(1, 1, -1) + except ValueError: + pass + m.close() + def test_anonymous(self): # anonymous mmap.mmap(-1, PAGE) m = mmap.mmap(-1, PAGESIZE) Index: Modules/mmapmodule.c =================================================================== --- Modules/mmapmodule.c (revision 70247) +++ Modules/mmapmodule.c (working copy) @@ -612,10 +612,8 @@ 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;