From 414c60ff16cd9d84028ce4df4580825fb59381e0 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 13 Nov 2026 11:58:18 +0100 Subject: [PATCH v2 4/7] Fixes for alloc_size attribute [numeric] "Short" Numeric values are now allocated with at least the size of the struct, so that accessing fields through the struct stays within the allocation. Discussion: https://www.postgresql.org/message-id/flat/cadec43a-d031-41cb-b887-3b4a29720017%40eisentraut.org --- src/backend/utils/adt/numeric.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index ff6dec42010..18a7877f194 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -7636,7 +7636,11 @@ make_result_safe(const NumericVar *var, Node *escontext) sign == NUMERIC_NINF)) elog(ERROR, "invalid numeric sign value 0x%x", sign); - result = (Numeric) palloc(NUMERIC_HDRSZ_SHORT); + /* + * We must allocate at least the full struct size, even though the + * datum only uses NUMERIC_HDRSZ_SHORT bytes. + */ + result = (Numeric) palloc(sizeof(struct NumericData)); SET_VARSIZE(result, NUMERIC_HDRSZ_SHORT); result->choice.n_header = sign; -- 2.56.0