From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexander Lakhin <exclusion@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17912: Invalid memory access when converting plpython' array containing empty array
Date: Fri, 28 Apr 2023 14:18:36 -0400
Message-ID: <1440309.1682705916@sss.pgh.pa.us> (raw)
In-Reply-To: <bf33fe9b-f2f8-5885-aae3-537cd4591386@gmail.com>
References: <17912-82ceed78731d9cdc@postgresql.org>
<1392974.1682694846@sss.pgh.pa.us>
<bf33fe9b-f2f8-5885-aae3-537cd4591386@gmail.com>
Alexander Lakhin <exclusion@gmail.com> writes:
> Thank you! I've read the message of the commit you just pushed,
> and I confirm that there are another oddities in that area. For example:
> CREATE OR REPLACE FUNCTION test() RETURNS text[] AS $$
> return [[1], 2]
> $$ LANGUAGE plpython3u;
> SELECT test();
> ERROR: wrong length of inner sequence: has length -1, but 1 was expected
> DETAIL: To construct a multidimensional array, the inner sequences must all have the same length.
Yeah. AFAICT, the idea of the existing code is to descend through
the first item at each nest level till we hit a non-list, then take
the lengths of those lists as the array dimensions, and then complain
if we find any later items that don't fit those dimensions. That leads
to some symmetry problems, in that the error you get for inconsistent
sequence lengths depends on the order in which the items are presented.
Also, it seems like there is something odd here:
regression=# CREATE OR REPLACE FUNCTION test() RETURNS text[] AS $$
regression$# return ["abc"]
regression$# $$ LANGUAGE plpython3u;
CREATE FUNCTION
regression=# select test();
test
-------
{abc}
(1 row)
regression=# CREATE OR REPLACE FUNCTION test() RETURNS text[] AS $$
return [[1,2,3], "abc"]
$$ LANGUAGE plpython3u;
CREATE FUNCTION
regression=# select test();
test
-------------------
{{1,2,3},{a,b,c}}
(1 row)
I think it's weird that "abc" is taken as a scalar in the first
case and a list in the second case. Even worse,
regression=# CREATE OR REPLACE FUNCTION test() RETURNS text[] AS $$
return ["abc", [1,2,3]]
$$ LANGUAGE plpython3u;
CREATE FUNCTION
regression=# select test();
test
-------------------
{abc,"[1, 2, 3]"}
(1 row)
This might be something that used to work more sanely with
Python 2 and got broken in Python 3 for the same reasons
discussed in bug #17908. I've not poked at it more though.
I don't think I have a Python 2 installation to test with
anymore :-(
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17912: Invalid memory access when converting plpython' array containing empty array
In-Reply-To: <1440309.1682705916@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox