diff options
-rw-r--r-- | src/pl/plpython/expected/plpython_types.out | 9 | ||||
-rw-r--r-- | src/pl/plpython/expected/plpython_types_3.out | 9 | ||||
-rw-r--r-- | src/pl/plpython/plpy_typeio.c | 19 | ||||
-rw-r--r-- | src/pl/plpython/sql/plpython_types.sql | 7 |
4 files changed, 32 insertions, 12 deletions
diff --git a/src/pl/plpython/expected/plpython_types.out b/src/pl/plpython/expected/plpython_types.out index 98b89b7d5c1..8e5a73ceedf 100644 --- a/src/pl/plpython/expected/plpython_types.out +++ b/src/pl/plpython/expected/plpython_types.out @@ -687,6 +687,15 @@ SELECT * FROM test_type_conversion_array_mixed2(); ERROR: invalid input syntax for type integer: "abc" CONTEXT: while creating return value PL/Python function "test_type_conversion_array_mixed2" +CREATE FUNCTION test_type_conversion_array_mixed3() RETURNS text[] AS $$ +return [[], 'a'] +$$ LANGUAGE plpythonu; +SELECT * FROM test_type_conversion_array_mixed3(); + test_type_conversion_array_mixed3 +----------------------------------- + {[],a} +(1 row) + CREATE FUNCTION test_type_conversion_mdarray_malformed() RETURNS int[] AS $$ return [[1,2,3],[4,5]] $$ LANGUAGE plpythonu; diff --git a/src/pl/plpython/expected/plpython_types_3.out b/src/pl/plpython/expected/plpython_types_3.out index a6ec10d5e18..4f72a626e18 100644 --- a/src/pl/plpython/expected/plpython_types_3.out +++ b/src/pl/plpython/expected/plpython_types_3.out @@ -687,6 +687,15 @@ SELECT * FROM test_type_conversion_array_mixed2(); ERROR: invalid input syntax for type integer: "abc" CONTEXT: while creating return value PL/Python function "test_type_conversion_array_mixed2" +CREATE FUNCTION test_type_conversion_array_mixed3() RETURNS text[] AS $$ +return [[], 'a'] +$$ LANGUAGE plpython3u; +SELECT * FROM test_type_conversion_array_mixed3(); + test_type_conversion_array_mixed3 +----------------------------------- + {[],a} +(1 row) + CREATE FUNCTION test_type_conversion_mdarray_malformed() RETURNS int[] AS $$ return [[1,2,3],[4,5]] $$ LANGUAGE plpython3u; diff --git a/src/pl/plpython/plpy_typeio.c b/src/pl/plpython/plpy_typeio.c index 47785735c30..dfe24d303ae 100644 --- a/src/pl/plpython/plpy_typeio.c +++ b/src/pl/plpython/plpy_typeio.c @@ -1151,7 +1151,7 @@ PLySequence_ToArray(PLyObToDatum *arg, PyObject *plrv, int i; Datum *elems; bool *nulls; - int64 len; + int len; int ndim; int dims[MAXDIM]; int lbs[MAXDIM]; @@ -1170,7 +1170,6 @@ PLySequence_ToArray(PLyObToDatum *arg, PyObject *plrv, * Determine the number of dimensions, and their sizes. */ ndim = 0; - len = 1; Py_INCREF(plrv); @@ -1186,13 +1185,6 @@ PLySequence_ToArray(PLyObToDatum *arg, PyObject *plrv, if (dims[ndim] < 0) PLy_elog(ERROR, "could not determine sequence length for function return value"); - if (dims[ndim] > MaxAllocSize) - PLy_elog(ERROR, "array size exceeds the maximum allowed"); - - len *= dims[ndim]; - if (len > MaxAllocSize) - PLy_elog(ERROR, "array size exceeds the maximum allowed"); - if (dims[ndim] == 0) { /* empty sequence */ @@ -1220,15 +1212,18 @@ PLySequence_ToArray(PLyObToDatum *arg, PyObject *plrv, PLy_elog(ERROR, "return value of function with array return type is not a Python sequence"); ndim = 1; - len = dims[0] = PySequence_Length(plrv); + dims[0] = PySequence_Length(plrv); } + /* Allocate space for work arrays, after detecting array size overflow */ + len = ArrayGetNItems(ndim, dims); + elems = palloc(sizeof(Datum) * len); + nulls = palloc(sizeof(bool) * len); + /* * Traverse the Python lists, in depth-first order, and collect all the * elements at the bottom level into 'elems'/'nulls' arrays. */ - elems = palloc(sizeof(Datum) * len); - nulls = palloc(sizeof(bool) * len); currelem = 0; PLySequence_ToArray_recurse(arg->u.array.elm, plrv, dims, ndim, 0, diff --git a/src/pl/plpython/sql/plpython_types.sql b/src/pl/plpython/sql/plpython_types.sql index cc0524ee806..8fa8f6bee7f 100644 --- a/src/pl/plpython/sql/plpython_types.sql +++ b/src/pl/plpython/sql/plpython_types.sql @@ -328,6 +328,13 @@ $$ LANGUAGE plpythonu; SELECT * FROM test_type_conversion_array_mixed2(); +CREATE FUNCTION test_type_conversion_array_mixed3() RETURNS text[] AS $$ +return [[], 'a'] +$$ LANGUAGE plpythonu; + +SELECT * FROM test_type_conversion_array_mixed3(); + + CREATE FUNCTION test_type_conversion_mdarray_malformed() RETURNS int[] AS $$ return [[1,2,3],[4,5]] $$ LANGUAGE plpythonu; |