r70879 - in python/trunk: Lib/test/test_mmap.py Modules/mmapmodule.c
Author: hirokazu.yamamoto Date: Tue Mar 31 22:14:04 2009 New Revision: 70879 Log: Issue #5387: Fixed mmap.move crash by integer overflow. (take2) Modified: python/trunk/Lib/test/test_mmap.py 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 22:14:04 2009 @@ -1,6 +1,6 @@ from test.test_support import TESTFN, run_unittest, import_module import unittest -import os, re +import os, re, itertools mmap = import_module('mmap') @@ -351,9 +351,21 @@ self.assertEqual(m[:], expected) m.close() - # should not crash - m = mmap.mmap(-1, 1) - self.assertRaises(ValueError, m.move, 1, 1, -1) + # segfault test (Issue 5387) + m = mmap.mmap(-1, 100) + offsets = [-100, -1, 0, 1, 100] + for source, dest, size in itertools.product(offsets, offsets, offsets): + try: + m.move(source, dest, size) + except ValueError: + pass + self.assertRaises(ValueError, m.move, -1, -1, -1) + self.assertRaises(ValueError, m.move, -1, -1, 0) + self.assertRaises(ValueError, m.move, -1, 0, -1) + self.assertRaises(ValueError, m.move, 0, -1, -1) + self.assertRaises(ValueError, m.move, -1, 0, 0) + self.assertRaises(ValueError, m.move, 0, -1, 0) + self.assertRaises(ValueError, m.move, 0, 0, -1) m.close() def test_anonymous(self): Modified: python/trunk/Modules/mmapmodule.c ============================================================================== --- python/trunk/Modules/mmapmodule.c (original) +++ python/trunk/Modules/mmapmodule.c Tue Mar 31 22:14:04 2009 @@ -617,7 +617,7 @@ } else { /* bounds check the values */ unsigned long pos = src > dest ? src : dest; - if (self->size >= pos && count > self->size - pos) { + if (self->size < pos || count > self->size - pos) { PyErr_SetString(PyExc_ValueError, "source or destination out of range"); return NULL;
FYI, PEP-8 Imports should usually be on separate lines, e.g.: Yes: import os import sys No: import sys, os On Tue, Mar 31, 2009 at 4:14 PM, hirokazu.yamamoto <python-checkins@python.org> wrote:
Author: hirokazu.yamamoto Date: Tue Mar 31 22:14:04 2009 New Revision: 70879
Log: Issue #5387: Fixed mmap.move crash by integer overflow. (take2)
Modified: python/trunk/Lib/test/test_mmap.py 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 22:14:04 2009 @@ -1,6 +1,6 @@ from test.test_support import TESTFN, run_unittest, import_module import unittest -import os, re +import os, re, itertools
mmap = import_module('mmap')
@@ -351,9 +351,21 @@ self.assertEqual(m[:], expected) m.close()
- # should not crash - m = mmap.mmap(-1, 1) - self.assertRaises(ValueError, m.move, 1, 1, -1) + # segfault test (Issue 5387) + m = mmap.mmap(-1, 100) + offsets = [-100, -1, 0, 1, 100] + for source, dest, size in itertools.product(offsets, offsets, offsets): + try: + m.move(source, dest, size) + except ValueError: + pass + self.assertRaises(ValueError, m.move, -1, -1, -1) + self.assertRaises(ValueError, m.move, -1, -1, 0) + self.assertRaises(ValueError, m.move, -1, 0, -1) + self.assertRaises(ValueError, m.move, 0, -1, -1) + self.assertRaises(ValueError, m.move, -1, 0, 0) + self.assertRaises(ValueError, m.move, 0, -1, 0) + self.assertRaises(ValueError, m.move, 0, 0, -1) m.close()
def test_anonymous(self):
Modified: python/trunk/Modules/mmapmodule.c ============================================================================== --- python/trunk/Modules/mmapmodule.c (original) +++ python/trunk/Modules/mmapmodule.c Tue Mar 31 22:14:04 2009 @@ -617,7 +617,7 @@ } else { /* bounds check the values */ unsigned long pos = src > dest ? src : dest; - if (self->size >= pos && count > self->size - pos) { + if (self->size < pos || count > self->size - pos) { PyErr_SetString(PyExc_ValueError, "source or destination out of range"); return NULL; _______________________________________________ Python-checkins mailing list Python-checkins@python.org http://mail.python.org/mailman/listinfo/python-checkins
FYI, PEP-8
Imports should usually be on separate lines, e.g.:
Yes: import os import sys
No: import sys, os
Yes, but "import os, re" was already there, I followed to it. I don't think it is so big deal... is it? Really required modification was, movement of m.close().
import mmap m = mmap.mmap(-1, 100) m.close() m.move(0, 0, 1) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: mmap closed or invalid
m.move() raises ValueError, but its meaning differs.
Jack diederich wrote:
FYI, PEP-8
Imports should usually be on separate lines, e.g.:
Yes: import os import sys
No: import sys, os
Of all the PEP 8 guidelines, I think that's the one that I deviate from most frequently. This is especially so for modules with names which are shorter than the import keyword itself (sys, os, re, time being the main offenders there). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------
participants (4)
-
Hirokazu Yamamoto
-
hirokazu.yamamoto
-
Jack diederich
-
Nick Coghlan