Re: v16dev: invalid memory alloc request size 8488348128

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Justin Pryzby <pryzby@telsasoft.com>
Cc: David Rowley <dgrowleyml@gmail.com>, pgsql-hackers@postgresql.org
Date: 2023-04-16T16:26:28Z
Lists: pgsql-hackers
Justin Pryzby <pryzby@telsasoft.com> writes:
> On Sat, Apr 15, 2023 at 11:33:58AM +1200, David Rowley wrote:
>> Any chance you could try and come up with a minimal reproducer?

> Try this

Thanks.  I see the problem: finalize_aggregate is no longer forcing
a R/W expanded datum returned by the finalfn into R/O form.  If
we re-use the aggregate result in multiple places, as this query
does, then the first use can clobber the value for later uses.
(The commit message specifically mentions this concern, so I wonder
how we failed to actually do it :-()

A minimal fix would be to force to R/O before returning from
finalize_aggregate, but I wonder if we should do it later.

By the by, I couldn't help noticing that ExecAggTransReparent
completely fails to do what its name promises it should do, ie
reparent a R/W datum into the proper context instead of physically
copying it.  That looks suspiciously like something that got broken
during some other refactoring somewhere along the line.  That'd be a
performance bug not a correctness bug, but it should be looked into.

			regards, tom lane



Commits

  1. Ensure result of an aggregate's finalfunc is made read-only.

  2. Remove uses of MemoryContextContains in nodeAgg.c and nodeWindowAgg.c.

  3. Fix pg_upgrade to detect non-upgradable anyarray usages.

  4. Work around cross-version-upgrade issues created by commit 9e38c2bb5.

  5. Declare assorted array functions using anycompatible not anyelement.