mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Enforce cube dimension limit in all cube construction functions
contrib/cube has a limit to 100 dimensions for cube datatype. However, it's not enforced everywhere, and one can actually construct cube with more than 100 dimensions having then trouble with dump/restore. This commit add checks for dimensions limit in all functions responsible for cube construction. Backpatch to all supported versions. Reported-by: Andrew Gierth Discussion: https://postgr.es/m/87va7uybt4.fsf%40news-spur.riddles.org.uk Author: Andrey Borodin with small additions by me Review: Tom Lane Backpatch-through: 9.3
This commit is contained in:
@ -190,6 +190,13 @@ cube_a_f8_f8(PG_FUNCTION_ARGS)
|
||||
errmsg("cannot work with arrays containing NULLs")));
|
||||
|
||||
dim = ARRNELEMS(ur);
|
||||
if (dim > CUBE_MAX_DIM)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("can't extend cube"),
|
||||
errdetail("A cube cannot have more than %d dimensions.",
|
||||
CUBE_MAX_DIM)));
|
||||
|
||||
if (ARRNELEMS(ll) != dim)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
|
||||
@ -231,6 +238,12 @@ cube_a_f8(PG_FUNCTION_ARGS)
|
||||
errmsg("cannot work with arrays containing NULLs")));
|
||||
|
||||
dim = ARRNELEMS(ur);
|
||||
if (dim > CUBE_MAX_DIM)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("array is too long"),
|
||||
errdetail("A cube cannot have more than %d dimensions.",
|
||||
CUBE_MAX_DIM)));
|
||||
|
||||
dur = ARRPTR(ur);
|
||||
|
||||
@ -267,6 +280,13 @@ cube_subset(PG_FUNCTION_ARGS)
|
||||
dx = (int32 *) ARR_DATA_PTR(idx);
|
||||
|
||||
dim = ARRNELEMS(idx);
|
||||
if (dim > CUBE_MAX_DIM)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("array is too long"),
|
||||
errdetail("A cube cannot have more than %d dimensions.",
|
||||
CUBE_MAX_DIM)));
|
||||
|
||||
size = offsetof(NDBOX, x[0]) +sizeof(double) * 2 * dim;
|
||||
result = (NDBOX *) palloc0(size);
|
||||
SET_VARSIZE(result, size);
|
||||
@ -1452,6 +1472,13 @@ cube_c_f8(PG_FUNCTION_ARGS)
|
||||
int size;
|
||||
int i;
|
||||
|
||||
if (c->dim + 1 > CUBE_MAX_DIM)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("can't extend cube"),
|
||||
errdetail("A cube cannot have more than %d dimensions.",
|
||||
CUBE_MAX_DIM)));
|
||||
|
||||
size = offsetof(NDBOX, x[0]) +sizeof(double) * (c->dim + 1) *2;
|
||||
result = (NDBOX *) palloc0(size);
|
||||
SET_VARSIZE(result, size);
|
||||
@ -1479,6 +1506,13 @@ cube_c_f8_f8(PG_FUNCTION_ARGS)
|
||||
int size;
|
||||
int i;
|
||||
|
||||
if (c->dim + 1 > CUBE_MAX_DIM)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("can't extend cube"),
|
||||
errdetail("A cube cannot have more than %d dimensions.",
|
||||
CUBE_MAX_DIM)));
|
||||
|
||||
size = offsetof(NDBOX, x[0]) +sizeof(double) * (c->dim + 1) *2;
|
||||
result = (NDBOX *) palloc0(size);
|
||||
SET_VARSIZE(result, size);
|
||||
|
Reference in New Issue
Block a user