From dcf206128aa2501f4b3cde012c4ed276c3f69b2d Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 12 May 2023 17:08:51 -0700 Subject: [PATCH] Check bounds unconditionally in array_to_vector(). (#127) Presently, array_to_vector()'s call to CheckDim() is skipped when typmod != -1, which allows for bypassing VECTOR_MAX_DIM. To fix, call Check[Expected]Dim() unconditionally. CheckExpectedDim() takes no action when typmod == -1, so there's no need to guard it with an 'if' statement. --- src/vector.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/vector.c b/src/vector.c index 7c128e5..ebb071a 100644 --- a/src/vector.c +++ b/src/vector.c @@ -396,10 +396,8 @@ array_to_vector(PG_FUNCTION_ARGS) get_typlenbyvalalign(ARR_ELEMTYPE(array), &typlen, &typbyval, &typalign); deconstruct_array(array, ARR_ELEMTYPE(array), typlen, typbyval, typalign, &elemsp, &nullsp, &nelemsp); - if (typmod == -1) - CheckDim(nelemsp); - else - CheckExpectedDim(typmod, nelemsp); + CheckDim(nelemsp); + CheckExpectedDim(typmod, nelemsp); result = InitVector(nelemsp); for (i = 0; i < nelemsp; i++)