Re: BUG #17912: Invalid memory access when converting plpython' array containing empty array
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2023-04-28T15:14:06Z
Lists: pgsql-bugs
Attachments
- fix-PLySequence_ToArray.patch (text/x-diff) patch
PG Bug reporting form <noreply@postgresql.org> writes: > CREATE EXTENSION plpython3u; > CREATE OR REPLACE FUNCTION test() RETURNS text[] AS $$ > return [[], "a"] > $$ LANGUAGE plpython3u; > SELECT test(); > As I can see, for the first case we get len = 0 in PLySequence_ToArray(); > elems, nulls palloc'ed with zero elements, but PLyObject_ToScalar() tries > to write a value into nulls[0]... Yeah. The calculation of the array size is being done in the wrong place, so that we may update len to zero before breaking out of the loop. But really it's poor coding for this function to be doing its own calculation of the array size at all, rather than consulting the authoritative ArrayGetNItems(). I think we need something like the attached. regards, tom lane
Commits
-
Tighten array dimensionality checks in Python -> SQL array conversion.
- b7fcf3824b42 12.15 landed
- b7001c6b6a77 15.3 landed
- aa7e5e404324 11.20 landed
- 9d517339e991 14.8 landed
- 0e6354ed9783 13.11 landed
- 0553528e7c2b 16.0 landed
-
Tighten array dimensionality checks in Perl -> SQL array conversion.
- f47004add160 16.0 landed
- ee24b5e792e0 13.11 landed
- ea96fbe772a7 11.20 landed
- ce9a1a3ea8fe 15.3 landed
- 900a8d526ff5 12.15 landed
- 1e868bb6c67a 14.8 landed
-
Handle zero-length sublist correctly in Python -> SQL array conversion.
- ff9203f46069 12.15 landed
- b7c6af375da6 11.20 landed
- a1d9aacc4128 14.8 landed
- 81eaaf65e393 16.0 landed
- 7dcd9998c19d 13.11 landed
- 512c555221c3 15.3 landed