aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/arrayfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-07-14 10:35:24 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2023-07-14 10:35:49 -0400
commitb8d3dae00f6c49d0c41abd5b36e2588a81abe5be (patch)
treef9e4b5c0ac4ca645007bf3207ea59cfc83f70d08 /src/backend/utils/adt/arrayfuncs.c
parent00f2a2556c9b23050e4f987e5d563b6856b83fc2 (diff)
downloadpostgresql-b8d3dae00f6c49d0c41abd5b36e2588a81abe5be.tar.gz
postgresql-b8d3dae00f6c49d0c41abd5b36e2588a81abe5be.zip
Improve error message for MaxAllocSize overrun in accumArrayResult.
Before, if you went past about 64M array elements in array_agg() and allied functions, you got a generic "invalid memory alloc request size" error. This patch replaces that with "array size exceeds the maximum allowed", which seems more user-friendly since it points you to needing to reduce the size of your array result. (This is the same error text you'd get from construct_md_array in the event of overrunning the maximum physical size for the finished array.) Per question from Shaozhong Shi. Since this hasn't come up often, I don't feel a need to back-patch. Discussion: https://postgr.es/m/CA+i5JwYtVS9z2E71PcNKAVPbOn4R2wuj-LqbJsYr_XOz73q7dQ@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/arrayfuncs.c')
-rw-r--r--src/backend/utils/adt/arrayfuncs.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index 4359dbd83df..7828a6264b5 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -5317,6 +5317,12 @@ accumArrayResult(ArrayBuildState *astate,
if (astate->nelems >= astate->alen)
{
astate->alen *= 2;
+ /* give an array-related error if we go past MaxAllocSize */
+ if (!AllocSizeIsValid(astate->alen * sizeof(Datum)))
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("array size exceeds the maximum allowed (%d)",
+ (int) MaxAllocSize)));
astate->dvalues = (Datum *)
repalloc(astate->dvalues, astate->alen * sizeof(Datum));
astate->dnulls = (bool *)