Re: BUG #18585: Date/time conversion functions are not protected against integer overflow

From: Joseph Koshakow <koshy44(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18585: Date/time conversion functions are not protected against integer overflow
Date: 2024-08-18 17:02:02
Message-ID: CAAvxfHc4jutMmVfRDwbxgeL7c6CKn4mpG+yfWTwcXCshM38FvA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> The date/time conversion functions do_to_timestamp(), DCH_from_char(),
> ... lack reliable checks for integer overflow in the input components.
...
> (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.)

The "v25-0001-Remove-dependence-on-fwrapv-semantics-in-some-da.patch"
patch in the linked thread above actually resolves some of these
issues. I took a brief look and it looks like most (possibly all) of
the remaining issues are due to unchecked arithmetic in the
`do_to_timestamp()` function in `formatting.c`. To resolve these issues
I would suggest someone go through that function and replace any
arithmetic that might overflow with the overflow-aware routines in
`int.h`. There are plenty of examples already in the
`do_to_timestamp()` function.

On Sun, Aug 18, 2024 at 12:53 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> If anybody does feel excited about the topic, I'm not going to stand
> in their way ... but I'm not excited.

I similarly do not plan on working on this but wanted to post the above
information for anyone who is interested.

Thanks,
Joseph Koshakow

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2024-08-19 01:20:06 Re: BUG #18582: fixed range of search for empty slot in SLRU
Previous Message Junwang Zhao 2024-08-18 14:46:45 Re: BUG #18559: Crash after detaching a partition concurrently from another session