Re: [PATCH] Fix interval input at minimum signed field values (BUG #19746)

From: Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com>
To: Tình Trần <tranvantinhnbk(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] Fix interval input at minimum signed field values (BUG #19746)
Date: 2026-11-04 11:15:44
Message-ID: CA+Y2Bmd00+GkrJ6-4BR_1wrKUtQo-BoEDzObTZKdhscA5=XkbA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Tinh,

> This is my first PostgreSQL patch submission, so feedback would be greatly
> appreciated.

Thanks for working on this. I tested v2 on master (77705d1e5a6).

The cases from the report are fixed: '-2562047788:00:54.775808' and
'@ 2147483648 days ago' (postgres_verbose) read back to the same value,
and the pg_dump example now restores both rows instead of none. The new
tests fail without the datetime.c change and pass with it, make check
passes, and pgindent is clean.

One problem: these are corner cases, but the commit message says
cancellation between fields near the limits should be preserved, and
with v2 that only holds for one field order. These return true on
unpatched master and fail with "interval field value out of range"
with v2:

SELECT interval_send('1 millisecond -9223372036854775808 us ago'::interval)
= interval_send('9223372036854774808 us'::interval);
SELECT interval_send('1 hour -9223372036854775808 us ago'::interval)
= interval_send('9223372033254775808 us'::interval);
SELECT interval_send('1 week -2147483648 days ago'::interval)
= interval_send('2147483641 days'::interval);
SELECT interval_send('-2147483648 months 0.5 years ago'::interval)
= interval_send('2147483642 months'::interval);

DecodeInterval reads fields right to left, so here the minimum field is
negated first and overflows before the other field can bring the total
back into range. The patch's cancellation tests put the minimum first in
the string, so they don't catch this. It would be good to test both
orders.

Smaller notes:

- Some inputs that are invalid either way now get a different error,
e.g. '2147483647 days 1 days ago' says "invalid input syntax" instead
of "field value out of range". That seems fine, since the real problem
is the repeated unit.
- v2 applies to master and REL_17-19, but not REL_15/16. REL_14 has
older input code and didn't show the problem in my tests.
- It isn't in a commitfest yet; registering it would get cfbot testing
it.

Regards,
Ishjaap Singh

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2026-11-04 11:19:54 Re: pg_threads.h take II
Previous Message Alvaro Herrera 2026-11-04 11:11:58 Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore