pgsql: Fix interval_mul() to not produce insane results.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix interval_mul() to not produce insane results.
Date: 2016-03-29 21:21:17
Message-ID: E1al14f-0000rC-GN@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix interval_mul() to not produce insane results.

interval_mul() attempts to prevent its calculations from producing silly
results, but it forgot that zero times infinity yields NaN in IEEE
arithmetic. Hence, a case like '1 second'::interval * 'infinity'::float8
produced a NaN for the months product, which didn't trigger the range
check, resulting in bogus and possibly platform-dependent output.

This isn't terribly obvious to the naked eye because if you try that
exact case, you get "interval out of range" which is what you expect
--- but if you look closer, the error is coming from interval_out not
interval_mul. interval_mul has allowed a bogus value into the system.

Fix by adding isnan tests.

Noted while testing Vitaly Burovoy's fix for infinity input to
to_timestamp(). Given the lack of field complaints, I doubt this
is worth a back-patch.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/a898b409f66f956e99694710f537829db02652c0

Modified Files
--------------
src/backend/utils/adt/timestamp.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2016-03-30 00:15:39 Re: Re: [COMMITTERS] pgsql: Sync tzload() and tzparse() APIs with IANA release tzcode2016c.
Previous Message Tom Lane 2016-03-29 21:09:42 pgsql: Allow to_timestamp(float8) to convert float infinity to timestam