Fixed infinite loop when parsing '{' as array

This commit is contained in:
Daniele Varrazzo 2012-09-20 03:19:24 +01:00
parent 0e644f6d95
commit 62a54f64f7
2 changed files with 5 additions and 1 deletions

View File

@ -260,6 +260,10 @@ typecast_GENERIC_ARRAY_cast(const char *str, Py_ssize_t len, PyObject *curs)
PyErr_SetString(DataError, "array does not start with '{'");
return NULL;
}
if (str[1] == '\0') {
PyErr_SetString(DataError, "malformed array: '{'");
return NULL;
}
Dprintf("typecast_GENERIC_ARRAY_cast: str = '%s',"
" len = " FORMAT_CODE_PY_SSIZE_T, str, len);

View File

@ -202,7 +202,7 @@ class TypesBasicTests(unittest.TestCase):
def testArrayMalformed(self):
curs = self.conn.cursor()
ss = ['', '{}}', '{' * 20 + '}' * 20]
ss = ['', '{', '{}}', '{' * 20 + '}' * 20]
for s in ss:
self.assertRaises(psycopg2.DataError,
psycopg2.extensions.STRINGARRAY, b(s), curs)