Skip to content

Commit 16caab0

Browse files
author
Hirokazu Yamamoto
committed
Merged revisions 70800 via svnmerge from
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. ........
1 parent 6bf6367 commit 16caab0

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

Lib/test/test_mmap.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,23 @@ def test_move(self):
335335
mf.close()
336336
f.close()
337337

338+
# more excessive test
339+
data = b"0123456789"
340+
for dest in range(len(data)):
341+
for src in range(len(data)):
342+
for count in range(len(data) - max(dest, src)):
343+
expected = data[:dest] + data[src:src+count] + data[dest+count:]
344+
m = mmap.mmap(-1, len(data))
345+
m[:] = data
346+
m.move(dest, src, count)
347+
self.assertEqual(m[:], expected)
348+
m.close()
349+
350+
# should not crash
351+
m = mmap.mmap(-1, 1)
352+
self.assertRaises(ValueError, m.move, 1, 1, -1)
353+
m.close()
354+
338355
def test_anonymous(self):
339356
# anonymous mmap.mmap(-1, PAGE)
340357
m = mmap.mmap(-1, PAGESIZE)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Core and Builtins
5353
Library
5454
-------
5555

56+
- Issue #5387: Fixed mmap.move crash by integer overflow.
57+
5658
- Issue #5261: Patch multiprocessing's semaphore.c to support context
5759
manager use: "with multiprocessing.Lock()" works now.
5860

Modules/mmapmodule.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,8 @@ mmap_move_method(mmap_object *self, PyObject *args)
623623
return NULL;
624624
} else {
625625
/* bounds check the values */
626-
if (/* end of source after end of data?? */
627-
((src+count) > self->size)
628-
/* dest will fit? */
629-
|| (dest+count > self->size)) {
626+
unsigned long pos = src > dest ? src : dest;
627+
if (self->size >= pos && count > self->size - pos) {
630628
PyErr_SetString(PyExc_ValueError,
631629
"source or destination out of range");
632630
return NULL;

0 commit comments

Comments
 (0)