diff options
Diffstat (limited to 'src/backend/executor/execExprInterp.c')
-rw-r--r-- | src/backend/executor/execExprInterp.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c index 0321a2d1c4b..9d997d71c9d 100644 --- a/src/backend/executor/execExprInterp.c +++ b/src/backend/executor/execExprInterp.c @@ -2689,7 +2689,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op) { /* Must be nested array expressions */ int nbytes = 0; - int nitems = 0; + int nitems; int outer_nelems = 0; int elem_ndims = 0; int *elem_dims = NULL; @@ -2784,9 +2784,14 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op) subbitmaps[outer_nelems] = ARR_NULLBITMAP(array); subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array); nbytes += subbytes[outer_nelems]; + /* check for overflow of total request */ + if (!AllocSizeIsValid(nbytes)) + ereport(ERROR, + (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), + errmsg("array size exceeds the maximum allowed (%d)", + (int) MaxAllocSize))); subnitems[outer_nelems] = ArrayGetNItems(this_ndims, ARR_DIMS(array)); - nitems += subnitems[outer_nelems]; havenulls |= ARR_HASNULL(array); outer_nelems++; } @@ -2820,7 +2825,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op) } /* check for subscript overflow */ - (void) ArrayGetNItems(ndims, dims); + nitems = ArrayGetNItems(ndims, dims); ArrayCheckBounds(ndims, dims, lbs); if (havenulls) @@ -2834,7 +2839,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op) nbytes += ARR_OVERHEAD_NONULLS(ndims); } - result = (ArrayType *) palloc(nbytes); + result = (ArrayType *) palloc0(nbytes); SET_VARSIZE(result, nbytes); result->ndim = ndims; result->dataoffset = dataoffset; |