Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit440b625

Browse files
committed
Detect more overflows in timestamp[tz]_pl_interval.
In commit25cd2d6 I (tgl) opined that "The additions of the monthsand microseconds fields could also overflow, of course. However,I believe we need no additional checks there; the existing rangechecks should catch such cases". This is demonstrably wrong howeverfor the microseconds field, and given that discovery it seems prudentto be paranoid about the months addition as well.Report and patch by Joseph Koshakow. As before, back-patch to allsupported branches. (However, the test case doesn't work beforev15 because we didn't allow wider-than-int32 numbers in intervalliterals. A variant test could probably be built that fits withinthat restriction, but it didn't seem worth the trouble.)Discussion:https://postgr.es/m/CAAvxfHf77sRHKoEzUw9_cMYSpbpNS2C+J_+8Dq4+0oi8iKopeA@mail.gmail.com
1 parent54aba93 commit440b625

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

‎src/backend/utils/adt/timestamp.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,7 +2854,10 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
28542854
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
28552855
errmsg("timestamp out of range")));
28562856

2857-
tm->tm_mon+=span->month;
2857+
if (pg_add_s32_overflow(tm->tm_mon,span->month,&tm->tm_mon))
2858+
ereport(ERROR,
2859+
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2860+
errmsg("timestamp out of range")));
28582861
if (tm->tm_mon>MONTHS_PER_YEAR)
28592862
{
28602863
tm->tm_year+= (tm->tm_mon-1) /MONTHS_PER_YEAR;
@@ -2906,7 +2909,10 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
29062909
errmsg("timestamp out of range")));
29072910
}
29082911

2909-
timestamp+=span->time;
2912+
if (pg_add_s64_overflow(timestamp,span->time,&timestamp))
2913+
ereport(ERROR,
2914+
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2915+
errmsg("timestamp out of range")));
29102916

29112917
if (!IS_VALID_TIMESTAMP(timestamp))
29122918
ereport(ERROR,
@@ -2968,7 +2974,10 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
29682974
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
29692975
errmsg("timestamp out of range")));
29702976

2971-
tm->tm_mon+=span->month;
2977+
if (pg_add_s32_overflow(tm->tm_mon,span->month,&tm->tm_mon))
2978+
ereport(ERROR,
2979+
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2980+
errmsg("timestamp out of range")));
29722981
if (tm->tm_mon>MONTHS_PER_YEAR)
29732982
{
29742983
tm->tm_year+= (tm->tm_mon-1) /MONTHS_PER_YEAR;
@@ -3027,7 +3036,10 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
30273036
errmsg("timestamp out of range")));
30283037
}
30293038

3030-
timestamp+=span->time;
3039+
if (pg_add_s64_overflow(timestamp,span->time,&timestamp))
3040+
ereport(ERROR,
3041+
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
3042+
errmsg("timestamp out of range")));
30313043

30323044
if (!IS_VALID_TIMESTAMP(timestamp))
30333045
ereport(ERROR,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp