Re: BUG #17912: Invalid memory access when converting plpython' array containing empty array

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexander Lakhin <exclusion(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17912: Invalid memory access when converting plpython' array containing empty array
Date: 2023-04-28 19:17:09
Message-ID: 1483429.1682709429@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I wrote:
> 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.

The real problem here is that we don't check that the list nesting
depth is the same throughout the array: if lists are more deeply
nested in later elements, we'll treat those sub-lists as scalars,
leading to inconsistent results. Conversely, a less-deeply-nested
list structure in a later element might still work, if it can be
treated as a sequence. I think the second and third examples
I gave should both throw errors.

I also notice that the error messages in this area speak of "sequences",
but it is more correct to call them "lists", because Python draws a
distinction. (All lists are sequences, but not vice versa, eg a
string is a sequence but not a list.)

So I'm thinking about the attached. I do not propose this for
back-patching, because it could break applications that work today.
But it seems like good tightening-up for HEAD, or maybe we should
wait for v17 at this point?

regards, tom lane

Attachment Content-Type Size
tighten-multidim-array-shape-checks.patch text/x-diff 6.3 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2023-04-28 19:21:31 Re: BUG #17911: Database or JDBC Driver Provides Incorrect Type
Previous Message Bruce Momjian 2023-04-28 18:47:57 Re: BUG #16628: Hostame and string connection functions