[Python-checkins] python/dist/src/Lib/test test_csv.py,1.19,1.20

andrewmcnamara at users.sourceforge.net andrewmcnamara at users.sourceforge.net
Tue Jan 11 08:32:06 CET 2005


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18525/Lib/test

Modified Files:
	test_csv.py 
Log Message:
Set an upper limit on the size of the field buffer, raise an exception
when this limit is reached. Limit defaults to 128k, and is changed
by module set_field_limit() method. Previously, an unmatched quote
character could result in the entire file being read into the field
buffer, potentially exhausting virtual memory.


Index: test_csv.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_csv.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- test_csv.py	11 Jan 2005 02:22:47 -0000	1.19
+++ test_csv.py	11 Jan 2005 07:32:02 -0000	1.20
@@ -229,10 +229,17 @@
                         quoting=csv.QUOTE_NONE, escapechar='\\')
 
     def test_read_bigfield(self):
-        # This exercises the buffer realloc functionality
-        bigstring = 'X' * 50000
+        # This exercises the buffer realloc functionality and field size
+        # limits.
+        size = 50000
+        bigstring = 'X' * size
         bigline = '%s,%s' % (bigstring, bigstring)
         self._read_test([bigline], [[bigstring, bigstring]])
+        csv.set_field_limit(size)
+        self._read_test([bigline], [[bigstring, bigstring]])
+        self.assertEqual(csv.set_field_limit(), size)
+        csv.set_field_limit(size-1)
+        self.assertRaises(csv.Error, self._read_test, [bigline], [])
 
 class TestDialectRegistry(unittest.TestCase):
     def test_registry_badargs(self):



More information about the Python-checkins mailing list