[Python-checkins] r70800 - in python/trunk: Lib/test/test_mmap.py Misc/NEWS Modules/mmapmodule.c
hirokazu.yamamoto
python-checkins at python.org
Tue Mar 31 15:13:05 CEST 2009
Author: hirokazu.yamamoto
Date: Tue Mar 31 15:13:05 2009
New Revision: 70800
Log:
Issue #5387: Fixed mmap.move crash by integer overflow.
Modified:
python/trunk/Lib/test/test_mmap.py
python/trunk/Misc/NEWS
python/trunk/Modules/mmapmodule.c
Modified: python/trunk/Lib/test/test_mmap.py
==============================================================================
--- python/trunk/Lib/test/test_mmap.py (original)
+++ python/trunk/Lib/test/test_mmap.py Tue Mar 31 15:13:05 2009
@@ -339,6 +339,23 @@
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)
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Tue Mar 31 15:13:05 2009
@@ -199,6 +199,8 @@
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.
Modified: python/trunk/Modules/mmapmodule.c
==============================================================================
--- python/trunk/Modules/mmapmodule.c (original)
+++ python/trunk/Modules/mmapmodule.c Tue Mar 31 15:13:05 2009
@@ -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;
More information about the Python-checkins
mailing list