Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Checkins

r70879 - in python/trunk: Lib/test/test_mmap.py Modules/mmapmodule.c

 

 

Python checkins RSS feed   Index | Next | Previous | View Threaded


python-checkins at python

Mar 31, 2009, 1:14 PM

Post #1 of 2 (62 views)
Permalink
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;
_______________________________________________
Python-checkins mailing list
Python-checkins[at]python.org
http://mail.python.org/mailman/listinfo/python-checkins


jackdied at gmail

Mar 31, 2009, 1:20 PM

Post #2 of 2 (57 views)
Permalink
Re: r70879 - in python/trunk: Lib/test/test_mmap.py Modules/mmapmodule.c [In reply to]

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[at]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[at]python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>
_______________________________________________
Python-checkins mailing list
Python-checkins[at]python.org
http://mail.python.org/mailman/listinfo/python-checkins

Python checkins RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.