Обсуждение: pgsql: Avoid ERRCODE_INTERNAL_ERROR in oracle_compat.c functions.

Поиск
Список
Период
Сортировка

pgsql: Avoid ERRCODE_INTERNAL_ERROR in oracle_compat.c functions.

От
Tom Lane
Дата:
Avoid ERRCODE_INTERNAL_ERROR in oracle_compat.c functions.

repeat() checked for integer overflow during its calculation of the
required output space, but it just passed the resulting integer to
palloc().  This meant that result sizes between 1GB and 2GB led to
ERRCODE_INTERNAL_ERROR, "invalid memory alloc request size" rather
than ERRCODE_PROGRAM_LIMIT_EXCEEDED, "requested length too large".
That seems like a bit of a wart, so add an explicit AllocSizeIsValid
check to make these error cases uniform.

Do likewise in the sibling functions lpad() etc.  While we're here,
also modernize their overflow checks to use pg_mul_s32_overflow() etc
instead of expensive divisions.

Per complaint from Japin Li.  This is basically cosmetic, so I don't
feel a need to back-patch.

Discussion: https://postgr.es/m/ME3P282MB16676ED32167189CB0462173B6D69@ME3P282MB1667.AUSP282.PROD.OUTLOOK.COM

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6217053f4e856159442629bd50c583ce3e4bc1fb

Modified Files
--------------
src/backend/utils/adt/oracle_compat.c | 43 +++++++++++++++++++----------------
1 file changed, 24 insertions(+), 19 deletions(-)