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: Fix overflow hazards in interval input and output conversions.
Date: Sat, 02 Apr 2022 20:12:39 +0000
Message-ID: <E1nak6w-0001zy-S7@gemulon.postgresql.org> (raw)

Fix overflow hazards in interval input and output conversions.

DecodeInterval (interval input) was careless about integer-overflow
hazards, allowing bogus results to be obtained for sufficiently
large input values.  Also, since it initially converted the input
to a "struct tm", it was impossible to produce the full range of
representable interval values.

Meanwhile, EncodeInterval (interval output) and a few other
functions could suffer failures if asked to process sufficiently
large interval values, because they also relied on being able to
represent an interval in "struct tm" which is not designed to
handle that.

Fix all this stuff by introducing new struct types that are more
fit for purpose.

While this is clearly a bug fix, it's also an API break for any
code that's calling these functions directly.  So back-patching
doesn't seem wise, especially in view of the lack of field
complaints.

Joe Koshakow, editorialized a bit by me

Discussion: https://postgr.es/m/CAAvxfHff0JLYHwyBrtMx_=6wr=k2Xp+D+-X3vEhHjJYMj+mQcg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e39f9904671082c5ad3a2c5acbdbd028fa93bf35

Modified Files
--------------
src/backend/utils/adt/datetime.c       | 734 +++++++++++++++++++++------------
src/backend/utils/adt/formatting.c     |  86 +++-
src/backend/utils/adt/timestamp.c      | 177 ++++----
src/include/datatype/timestamp.h       |  39 ++
src/include/pgtime.h                   |   3 +
src/include/utils/datetime.h           |   6 +-
src/include/utils/timestamp.h          |   5 +-
src/test/regress/expected/interval.out | 611 +++++++++++++++++++++++++++
src/test/regress/sql/interval.sql      | 184 +++++++++
9 files changed, 1473 insertions(+), 372 deletions(-)



Message-ID: <E1nak6w-0001zy-S7@gemulon.postgresql.org>
Permalink:  ../E1nak6w-0001zy-S7@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nak6w-0001zy-S7@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: Fix overflow hazards in interval input and output conversions.
  In-Reply-To: <E1nak6w-0001zy-S7@gemulon.postgresql.org>
  References: <E1nak6w-0001zy-S7@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