]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 70690,70692 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 29 Mar 2009 19:03:52 +0000 (19:03 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 29 Mar 2009 19:03:52 +0000 (19:03 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r70690 | antoine.pitrou | 2009-03-29 20:40:13 +0200 (dim., 29 mars 2009) | 3 lines

  Fix leak in _fileio.c (patch by Hirokazu Yamamoto)
........
  r70692 | antoine.pitrou | 2009-03-29 20:55:12 +0200 (dim., 29 mars 2009) | 4 lines

  Plug another leak, and finally add a test for #1174606 (read() from /dev/zero).
  The leak was the reason my previous attempts at testing failed...
........

Lib/test/test_io.py
Modules/_fileio.c

index 598e391d43536c41cf7da6d74515f0fcaef3e49b..98fcbf904624dc1ae970e022da0bc047ac2b7498 100644 (file)
@@ -305,6 +305,22 @@ class IOTest(unittest.TestCase):
             file = io.open(f.fileno(), "r", closefd=False)
             self.assertEqual(file.buffer.raw.closefd, False)
 
+    def test_unbounded_file(self):
+        # Issue #1174606: reading from an unbounded stream such as /dev/zero.
+        zero = "/dev/zero"
+        if not os.path.exists(zero):
+            return     # /dev/zero does not exist
+        if sys.maxsize > 0x7FFFFFFF:
+            return     # test can only run in a 32-bit address space
+        if support.real_max_memuse < support._2G:
+            return     # test requires at least 2GB of memory
+        with open(zero, "rb", buffering=0) as f:
+            self.assertRaises(OverflowError, f.read)
+        with open(zero, "rb") as f:
+            self.assertRaises(OverflowError, f.read)
+        with open(zero, "r") as f:
+            self.assertRaises(OverflowError, f.read)
+
 
 class MemorySeekTestMixin:
 
index 919fdea80421395280281b8f80660fab384f3cfb..f718d703f8dab3fc307c0582ac361f370d78bbc9 100644 (file)
@@ -465,6 +465,7 @@ fileio_readall(PyFileIOObject *self)
                        PyErr_SetString(PyExc_OverflowError,
                                "unbounded read returned more bytes "
                                "than a Python string can hold ");
+                       Py_DECREF(result);
                        return NULL;
                }
 
@@ -541,6 +542,7 @@ fileio_read(PyFileIOObject *self, PyObject *args)
        Py_END_ALLOW_THREADS
 
        if (n < 0) {
+               Py_DECREF(bytes);
                if (errno == EAGAIN)
                        Py_RETURN_NONE;
                PyErr_SetFromErrno(PyExc_IOError);