pgsql: Avoid ERRCODE_INTERNAL_ERROR in oracle_compat.c functions.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid ERRCODE_INTERNAL_ERROR in oracle_compat.c functions.
Date: 2022-05-26 16:25:27
Message-ID: E1nuGIg-001FWH-VD@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2022-05-26 16:57:12 pgsql: In CREATE FOREIGN TABLE syntax synopsis, fix partitioning stuff.
Previous Message Bruce Momjian 2022-05-26 02:19:47 pgsql: relnotes: update ordered partition scan item