pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: exclusion@gmail.com
Subject: BUG #18585: Date/time conversion functions are not protected against integer overflow
Date: Sat, 17 Aug 2024 15:00:01 +0000
Message-ID: <18585-db646741dd649abd@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      18585
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 17beta3
Operating system:   Ubuntu 22.04
Description:        

The date/time conversion functions do_to_timestamp(), DCH_from_char(),
... lack reliable checks for integer overflow in the input components.

1) Millennium:
SELECT to_timestamp('2147483647,999', 'Y,YYY');
       to_timestamp        
---------------------------
 0001-01-01 00:00:00+00 BC
vs
SELECT to_timestamp('2147483,999', 'Y,YYY');
ERROR:  timestamp out of range

2) Century:
SELECT to_date('-2147483648', 'CC');
  to_date   
------------
 0001-01-01
vs
SELECT to_date('-21474836', 'CC');
ERROR:  date out of range: "-21474836"

3) Century + year:
SELECT to_date('-2147483648 01', 'CC YY');
  to_date   
------------
 0100-01-01
vs
SELECT to_date('-21474836 01', 'CC YY');
ERROR:  date out of range: "-21474836 01"

4) Milliseconds:
SELECT to_timestamp('0.-2147483648', 'SS.MS');
       to_timestamp        
---------------------------
 0001-01-01 00:00:00+00 BC
vs
SELECT to_timestamp('0.-2147483', 'SS.MS');
ERROR:  date/time field value out of range: "0.-2147483"

5) Week of month:
SELECT to_timestamp('613566758', 'W');
       to_timestamp        
---------------------------
 0001-01-04 00:00:00+00 BC
vs
SELECT to_timestamp('613566750', 'W');
ERROR:  date/time field value out of range: "613566750"

6) Week number of year:
SELECT to_timestamp('2024 613566758 1', 'YYYY WW D');
      to_timestamp      
------------------------
 2024-01-04 00:00:00+00
vs
SELECT to_timestamp('2024 61356675 1', 'YYYY WW D');
ERROR:  date/time field value out of range: "2024 61356675 1"

7)  ISO Week:
SELECT to_date('2024 613566758 1', 'IYYY IW ID');
  to_date   
------------
 2024-01-04
vs
SELECT to_date('2024 61356675 1', 'IYYY IW ID');
    to_date    
---------------
 1177946-01-28

Observed on REL_12_STABLE .. master.

(A couple of such anomalies were noticed at
https://www.postgresql.org/message-id/31ad2cd1-db94-bdb3-f91a-65ffdb4bef95%40gmail.com,
but as these ones trigger an incorrect behaviour even without -ftrapv and
in the back branches, maybe it's better to fix these defects separately.)



view thread (4+ messages)  latest in thread

Message-ID: <18585-db646741dd649abd@postgresql.org>
Permalink:  ../18585-db646741dd649abd@postgresql.org/
Also on:    postgresql.org/message-id/18585-db646741dd649abd@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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, exclusion@gmail.com
  Subject: Re: BUG #18585: Date/time conversion functions are not protected against integer overflow
  In-Reply-To: <18585-db646741dd649abd@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