pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Array parsing incorrectly accepts ragged multidimensional arrays
3+ messages / 2 participants
[nested] [flat]

* Array parsing incorrectly accepts ragged multidimensional arrays
@ 2023-06-04 22:39 Nikhil Benesch <nikhil.benesch@gmail.com>
  2023-06-04 22:53 ` Re: Array parsing incorrectly accepts ragged multidimensional arrays Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Nikhil Benesch @ 2023-06-04 22:39 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: Sean Loiselle <himself@seanloiselle.com>

While working on Postgres-compatible array support in Materialize, my
colleague Sean Loiselle (CC'd) discovered what a class of seemingly
invalid array values that are accepted by Postgres's array input
routine:

benesch=# select '{{{9}},{8},{7}}'::int[];
 int4
------
 {}
(1 row)

benesch=# select '{{9},{{8}},{7}}'::int[];
 int4
------
 {}
(1 row)

benesch=# select '{{9},{8},{{7}}}'::int[];
          int4
------------------------
 {{{9}},{{NULL}},{{7}}}
(1 row)

As far as we can tell, Postgres *should* reject all these array
values, as the elements of each dimension do not have uniform length.

Postgres does correctly reject the analogous test cases with one less
layer of nesting:

benesch=# select '{{1}, 2, 3}'::int[];
ERROR:  malformed array literal: "{{1}, 2, 3}"
LINE 1: select '{{1}, 2, 3}'::int[];
               ^
DETAIL:  Unexpected array element.
benesch=# select '{1, {2}, 3}'::int[];
ERROR:  malformed array literal: "{1, {2}, 3}"
LINE 1: select '{1, {2}, 3}'::int[];
               ^
DETAIL:  Unexpected "{" character.
benesch=# select '{1, 2, {3}}'::int[];
ERROR:  malformed array literal: "{1, 2, {3}}"
LINE 1: select '{1, 2, {3}}'::int[];
               ^
DETAIL:  Unexpected "{" character.

I whipped up a patch that causes Postgres to correctly reject the
three examples above [0], but I am not convinced of its correctness.

Do folks agree that this is a bug? Is it worth me or Sean formally
submitting the proposed patch, or would someone with more experience
like to do a more thorough refactor of the ArrayCount routine?

[0]: https://gist.github.com/benesch/2e77712f81625deeb0e2246098fd8089





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Array parsing incorrectly accepts ragged multidimensional arrays
  2023-06-04 22:39 Array parsing incorrectly accepts ragged multidimensional arrays Nikhil Benesch <nikhil.benesch@gmail.com>
@ 2023-06-04 22:53 ` Tom Lane <tgl@sss.pgh.pa.us>
  2023-06-05 01:02   ` Re: Array parsing incorrectly accepts ragged multidimensional arrays Nikhil Benesch <nikhil.benesch@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2023-06-04 22:53 UTC (permalink / raw)
  To: Nikhil Benesch <nikhil.benesch@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org, Sean Loiselle <himself@seanloiselle.com>

Nikhil Benesch <nikhil.benesch@gmail.com> writes:
> While working on Postgres-compatible array support in Materialize, my
> colleague Sean Loiselle (CC'd) discovered what a class of seemingly
> invalid array values that are accepted by Postgres's array input
> routine:

Yeah, see existing thread (and patch) at

https://www.postgresql.org/message-id/flat/2794005.1683042087@sss.pgh.pa.us

Please review that if you'd like.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Array parsing incorrectly accepts ragged multidimensional arrays
  2023-06-04 22:39 Array parsing incorrectly accepts ragged multidimensional arrays Nikhil Benesch <nikhil.benesch@gmail.com>
  2023-06-04 22:53 ` Re: Array parsing incorrectly accepts ragged multidimensional arrays Tom Lane <tgl@sss.pgh.pa.us>
@ 2023-06-05 01:02   ` Nikhil Benesch <nikhil.benesch@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Nikhil Benesch @ 2023-06-05 01:02 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs@lists.postgresql.org, Sean Loiselle <himself@seanloiselle.com>

Ah, thanks for the pointer. Funny how these bugs can go unnoticed for
two decades and then get noticed twice in the same month.

On Sun, Jun 4, 2023 at 6:53 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Nikhil Benesch <nikhil.benesch@gmail.com> writes:
> > While working on Postgres-compatible array support in Materialize, my
> > colleague Sean Loiselle (CC'd) discovered what a class of seemingly
> > invalid array values that are accepted by Postgres's array input
> > routine:
>
> Yeah, see existing thread (and patch) at
>
> https://www.postgresql.org/message-id/flat/2794005.1683042087@sss.pgh.pa.us
>
> Please review that if you'd like.
>
>                         regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2023-06-05 01:02 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-06-04 22:39 Array parsing incorrectly accepts ragged multidimensional arrays Nikhil Benesch <nikhil.benesch@gmail.com>
2023-06-04 22:53 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-06-05 01:02   ` Nikhil Benesch <nikhil.benesch@gmail.com>

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