pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid ERRCODE_INTERNAL_ERROR in oracle_compat.c functions.
Date: Thu, 26 May 2022 16:25:27 +0000
Message-ID: <E1nuGIg-001FWH-VD@gemulon.postgresql.org> (raw)

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



Message-ID: <E1nuGIg-001FWH-VD@gemulon.postgresql.org>
Permalink:  ../E1nuGIg-001FWH-VD@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nuGIg-001FWH-VD@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Avoid ERRCODE_INTERNAL_ERROR in oracle_compat.c functions.
  In-Reply-To: <E1nuGIg-001FWH-VD@gemulon.postgresql.org>
  References: <E1nuGIg-001FWH-VD@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox