1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

Reject "23:59:60.nnn" in datetime input.

It's intentional that we don't allow values greater than 24 hours,
while we do allow "24:00:00" as well as "23:59:60" as inputs.
However, the range check was miscoded in such a way that it would
accept "23:59:60.nnn" with a nonzero fraction.  For time or timetz,
the stored result would then be greater than "24:00:00" which would
fail dump/reload, not to mention possibly confusing other operations.

Fix by explicitly calculating the result and making sure it does not
exceed 24 hours.  (This calculation is redundant with what will happen
later in tm2time or tm2timetz.  Maybe someday somebody will find that
annoying enough to justify refactoring to avoid the duplication; but
that seems too invasive for a back-patched bug fix, and the cost is
probably unmeasurable anyway.)

Note that this change also rejects such input as the time portion
of a timestamp(tz) value.

Back-patch to v10.  The bug is far older, but to change this pre-v10
we'd need to ensure that the logic behaves sanely with float timestamps,
which is possibly nontrivial due to roundoff considerations.
Doesn't really seem worth troubling with.

Per report from Christoph Berg.

Discussion: https://postgr.es/m/20200520125807.GB296739@msg.df7cb.de
This commit is contained in:
Tom Lane
2020-06-04 16:42:08 -04:00
parent 03aa25b6e3
commit a958b07bc4
8 changed files with 176 additions and 38 deletions

View File

@ -73,6 +73,47 @@ SELECT f1 AS "Eight" FROM TIME_TBL WHERE f1 >= '00:00';
15:36:39
(10 rows)
-- Check edge cases
SELECT '23:59:59.999999'::time;
time
-----------------
23:59:59.999999
(1 row)
SELECT '23:59:59.9999999'::time; -- rounds up
time
----------
24:00:00
(1 row)
SELECT '23:59:60'::time; -- rounds up
time
----------
24:00:00
(1 row)
SELECT '24:00:00'::time; -- allowed
time
----------
24:00:00
(1 row)
SELECT '24:00:00.01'::time; -- not allowed
ERROR: date/time field value out of range: "24:00:00.01"
LINE 1: SELECT '24:00:00.01'::time;
^
SELECT '23:59:60.01'::time; -- not allowed
ERROR: date/time field value out of range: "23:59:60.01"
LINE 1: SELECT '23:59:60.01'::time;
^
SELECT '24:01:00'::time; -- not allowed
ERROR: date/time field value out of range: "24:01:00"
LINE 1: SELECT '24:01:00'::time;
^
SELECT '25:00:00'::time; -- not allowed
ERROR: date/time field value out of range: "25:00:00"
LINE 1: SELECT '25:00:00'::time;
^
--
-- TIME simple math
--

View File

@ -90,6 +90,47 @@ SELECT f1 AS "Ten" FROM TIMETZ_TBL WHERE f1 >= '00:00-07';
15:36:39-04
(12 rows)
-- Check edge cases
SELECT '23:59:59.999999'::timetz;
timetz
--------------------
23:59:59.999999-07
(1 row)
SELECT '23:59:59.9999999'::timetz; -- rounds up
timetz
-------------
24:00:00-07
(1 row)
SELECT '23:59:60'::timetz; -- rounds up
timetz
-------------
24:00:00-07
(1 row)
SELECT '24:00:00'::timetz; -- allowed
timetz
-------------
24:00:00-07
(1 row)
SELECT '24:00:00.01'::timetz; -- not allowed
ERROR: date/time field value out of range: "24:00:00.01"
LINE 1: SELECT '24:00:00.01'::timetz;
^
SELECT '23:59:60.01'::timetz; -- not allowed
ERROR: date/time field value out of range: "23:59:60.01"
LINE 1: SELECT '23:59:60.01'::timetz;
^
SELECT '24:01:00'::timetz; -- not allowed
ERROR: date/time field value out of range: "24:01:00"
LINE 1: SELECT '24:01:00'::timetz;
^
SELECT '25:00:00'::timetz; -- not allowed
ERROR: date/time field value out of range: "25:00:00"
LINE 1: SELECT '25:00:00'::timetz;
^
--
-- TIME simple math
--

View File

@ -30,6 +30,16 @@ SELECT f1 AS "None" FROM TIME_TBL WHERE f1 < '00:00';
SELECT f1 AS "Eight" FROM TIME_TBL WHERE f1 >= '00:00';
-- Check edge cases
SELECT '23:59:59.999999'::time;
SELECT '23:59:59.9999999'::time; -- rounds up
SELECT '23:59:60'::time; -- rounds up
SELECT '24:00:00'::time; -- allowed
SELECT '24:00:00.01'::time; -- not allowed
SELECT '23:59:60.01'::time; -- not allowed
SELECT '24:01:00'::time; -- not allowed
SELECT '25:00:00'::time; -- not allowed
--
-- TIME simple math
--

View File

@ -35,6 +35,16 @@ SELECT f1 AS "None" FROM TIMETZ_TBL WHERE f1 < '00:00-07';
SELECT f1 AS "Ten" FROM TIMETZ_TBL WHERE f1 >= '00:00-07';
-- Check edge cases
SELECT '23:59:59.999999'::timetz;
SELECT '23:59:59.9999999'::timetz; -- rounds up
SELECT '23:59:60'::timetz; -- rounds up
SELECT '24:00:00'::timetz; -- allowed
SELECT '24:00:00.01'::timetz; -- not allowed
SELECT '23:59:60.01'::timetz; -- not allowed
SELECT '24:01:00'::timetz; -- not allowed
SELECT '25:00:00'::timetz; -- not allowed
--
-- TIME simple math
--