mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
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.
This commit is contained in:
parent
29bf4e44f6
commit
e4d05c4f93
3 changed files with 87 additions and 32 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue