summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAndrew McNamara <andrewm@object-craft.com.au>2005-01-11 07:32:02 (GMT)
committerAndrew McNamara <andrewm@object-craft.com.au>2005-01-11 07:32:02 (GMT)
commite4d05c4f93d0cf4359a5df5862110d94c8216de4 (patch)
treeb4524838f7fa31ca4c4f68f4a22597b194ebd9aa /Lib
parent29bf4e44f6392e402f15512e80295750691d436a (diff)
downloadcpython-e4d05c4f93d0cf4359a5df5862110d94c8216de4.zip
cpython-e4d05c4f93d0cf4359a5df5862110d94c8216de4.tar.gz
cpython-e4d05c4f93d0cf4359a5df5862110d94c8216de4.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/csv.py1
-rw-r--r--Lib/test/test_csv.py11
2 files changed, 10 insertions, 2 deletions
diff --git a/Lib/csv.py b/Lib/csv.py
index 37bdba5..aaaa3cf 100644
--- a/Lib/csv.py
+++ b/Lib/csv.py
@@ -6,6 +6,7 @@ csv.py - read/write/investigate CSV files
import re
from _csv import Error, __version__, writer, reader, register_dialect, \
unregister_dialect, get_dialect, list_dialects, \
+ set_field_limit, \
QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE, \
__doc__
from _csv import Dialect as _Dialect
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index ff45b61..82a36e9 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -229,10 +229,17 @@ class Test_Csv(unittest.TestCase):
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):