mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-11 19:46:36 +03:00
Fixed return value after malformed arrays
This commit is contained in:
parent
fc5cc1df01
commit
72e9cf7b6d
|
@ -212,8 +212,10 @@ typecast_array_scan(const char *str, Py_ssize_t strlength,
|
||||||
PyList_Append(array, sub);
|
PyList_Append(array, sub);
|
||||||
Py_DECREF(sub);
|
Py_DECREF(sub);
|
||||||
|
|
||||||
if (stack_index == MAX_DIMENSIONS)
|
if (stack_index == MAX_DIMENSIONS) {
|
||||||
|
PyErr_SetString(DataError, "excessive array dimensions");
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
stack[stack_index++] = array;
|
stack[stack_index++] = array;
|
||||||
array = sub;
|
array = sub;
|
||||||
|
@ -224,8 +226,10 @@ typecast_array_scan(const char *str, Py_ssize_t strlength,
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (state == ASCAN_END) {
|
else if (state == ASCAN_END) {
|
||||||
if (stack_index == 0)
|
if (stack_index == 0) {
|
||||||
|
PyErr_SetString(DataError, "unbalanced braces in array");
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
array = stack[--stack_index];
|
array = stack[--stack_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +257,7 @@ typecast_GENERIC_ARRAY_cast(const char *str, Py_ssize_t len, PyObject *curs)
|
||||||
if (str[0] == '[')
|
if (str[0] == '[')
|
||||||
typecast_array_cleanup(&str, &len);
|
typecast_array_cleanup(&str, &len);
|
||||||
if (str[0] != '{') {
|
if (str[0] != '{') {
|
||||||
PyErr_SetString(Error, "array does not start with '{'");
|
PyErr_SetString(DataError, "array does not start with '{'");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,13 @@ class TypesBasicTests(unittest.TestCase):
|
||||||
r = self.execute("SELECT %s AS foo", (ss,))
|
r = self.execute("SELECT %s AS foo", (ss,))
|
||||||
self.failUnlessEqual(ss, r)
|
self.failUnlessEqual(ss, r)
|
||||||
|
|
||||||
|
def testArrayMalformed(self):
|
||||||
|
curs = self.conn.cursor()
|
||||||
|
ss = ['', '{}}', '{' * 20 + '}' * 20]
|
||||||
|
for s in ss:
|
||||||
|
self.assertRaises(psycopg2.DataError,
|
||||||
|
psycopg2.extensions.STRINGARRAY, b(s), curs)
|
||||||
|
|
||||||
@testutils.skip_from_python(3)
|
@testutils.skip_from_python(3)
|
||||||
def testTypeRoundtripBuffer(self):
|
def testTypeRoundtripBuffer(self):
|
||||||
o1 = buffer("".join(map(chr, range(256))))
|
o1 = buffer("".join(map(chr, range(256))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user