Re: [PATCH] Fix float8 parsing of denormal values (on some platforms?)

Lists: pgsql-hackers
From: Marti Raudsepp <marti(at)juffo(dot)org>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
Subject: [PATCH] Fix float8 parsing of denormal values (on some platforms?)
Date: 2011-12-21 16:21:10
Message-ID: CABRT9RAxA7nxwd-0nVEgv3D+-nuYfFwJzUZt=meL_ZT2SKPsHw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi list,

Back in June we had a discussion about parsing denormal floating-point
values. A float8->text conversion could result in a number that can't
be converted back to float8 anymore for some values. Among other
things, this could break backups (though my searches didn't turn up
any reports of this ever happening).

The reason is that Linux strtod() sets errno=ERANGE for denormal
numbers. This behavior is also explicitly allowed
(implementation-defined) by the C99 standard.

Further analysis was done by Jeroen Vermeulen here:
http://archives.postgresql.org/pgsql-hackers/2011-06/msg01773.php

I think the least invasive fix, as proposed by Jeroen, is to fail only
when ERANGE is set *and* the return value is 0.0 or +/-HUGE_VAL.
Reading relevant specifications, this seems to be a fairly safe
assumption. That's what the attached patch does.

(I also updated the float4in function, but that's not strictly
necessary -- it would fail later in CHECKFLOATVAL() anyway)

What I don't know is how many platforms are actually capable of
parsing denormal double values. I added some regression tests, it
would be interesting to see results from pgbuildfarm and potentially
revert these tests later.

Regards,
Marti


From: Marti Raudsepp <marti(at)juffo(dot)org>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
Subject: Re: [PATCH] Fix float8 parsing of denormal values (on some platforms?)
Date: 2011-12-21 16:24:17
Message-ID: CABRT9RDLx_Zs_zz2=vhH3L2h-20n9Rs5XskOsqoyfWj3tUbfdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Dec 21, 2011 at 18:21, Marti Raudsepp <marti(at)juffo(dot)org> wrote:
> I think the least invasive fix, as proposed by Jeroen, is to fail only
> when ERANGE is set *and* the return value is 0.0 or +/-HUGE_VAL.
> Reading relevant specifications, this seems to be a fairly safe
> assumption. That's what the attached patch does.

Oops, now attached the patch too.

Regards,
Marti

Attachment Content-Type Size
float8-denormal-parsing.patch text/x-patch 3.5 KB

From: Abhijit Menon-Sen <ams(at)toroid(dot)org>
To: Marti Raudsepp <marti(at)juffo(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org, Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
Subject: Re: [PATCH] Fix float8 parsing of denormal values (on some platforms?)
Date: 2012-01-26 15:57:02
Message-ID: 20120126155702.GE30769@toroid.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

At 2011-12-21 18:24:17 +0200, marti(at)juffo(dot)org wrote:
>
> > I think the least invasive fix, as proposed by Jeroen, is to fail only
> > when ERANGE is set *and* the return value is 0.0 or +/-HUGE_VAL.
> > Reading relevant specifications, this seems to be a fairly safe
> > assumption. That's what the attached patch does.
>
> Oops, now attached the patch too.

Approach seems sensible, patch applies, builds, and passes tests.
Marking ready for committer and crossing fingers about buildfarm
failures…

-- ams


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marti Raudsepp <marti(at)juffo(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
Subject: Re: [PATCH] Fix float8 parsing of denormal values (on some platforms?)
Date: 2012-02-01 18:17:46
Message-ID: 21278.1328120266@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Marti Raudsepp <marti(at)juffo(dot)org> writes:
> On Wed, Dec 21, 2011 at 18:21, Marti Raudsepp <marti(at)juffo(dot)org> wrote:
>> I think the least invasive fix, as proposed by Jeroen, is to fail only
>> when ERANGE is set *and* the return value is 0.0 or +/-HUGE_VAL.
>> Reading relevant specifications, this seems to be a fairly safe
>> assumption. That's what the attached patch does.

> Oops, now attached the patch too.

Applied with minor revisions. Notably, after staring at the code a bit
I got uncomfortable with its assumption that pg_strncasecmp() cannot
change errno, so I fixed it to not assume that. Also, on some platforms
HUGE_VAL isn't infinity but the largest finite value, so I made the
range tests be like ">= HUGE_VAL" not just "== HUGE_VAL". I know the
man page for strtod() specifies it should return exactly HUGE_VAL for
overflow, but who's to say that <math.h> is on the same page as the
actual function?

regards, tom lane


From: Marti Raudsepp <marti(at)juffo(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
Subject: Re: [PATCH] Fix float8 parsing of denormal values (on some platforms?)
Date: 2012-02-02 10:16:26
Message-ID: CABRT9RDXtPoVHxrr2YfcQHC_u=F34pp-peo-Yy5WhztN3ZeiEA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Feb 1, 2012 at 20:17, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Applied with minor revisions.

Thanks! :)

We're already seeing first buildfarm failures, on system "narwhal"
using an msys/mingw compiler.
http://www.pgbuildfarm.org/cgi-bin/show_log.pl?nm=narwhal&dt=2012-02-02%2005%3A00%3A02

No idea which libc it uses though. The MSVC libc looks fine because
"currawong" passes these tests.

PS: it would be useful to have the output of 'cc -v' in buildfarm
reports since the "Compiler" field may be out of date.

Regards,
Marti


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marti Raudsepp <marti(at)juffo(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
Subject: Re: [PATCH] Fix float8 parsing of denormal values (on some platforms?)
Date: 2012-02-03 08:49:38
Message-ID: 14168.1328258978@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Marti Raudsepp <marti(at)juffo(dot)org> writes:
> We're already seeing first buildfarm failures, on system "narwhal"
> using an msys/mingw compiler.

Yeah. After a full day's cycle, the answer seems to be that
denormalized input works fine everywhere except:

1. mingw on Windows (even though MSVC builds work)

2. some Gentoo builds fail (knowing that platform, the phase of the moon
is probably the most predictable factor determining this).

I'm inclined at this point to remove the regression test cases, because
we have no principled way to deal with case #2. We could install
alternative "expected" files that accept the failure, but then what's
the point of having the test case at all?

It might be worth pressuring the mingw folk to get with the program,
but I'm not going to be the one to do that.

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Marti Raudsepp <marti(at)juffo(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Jeroen Vermeulen <jtv(at)xs4all(dot)nl>
Subject: Re: [PATCH] Fix float8 parsing of denormal values (on some platforms?)
Date: 2012-02-03 09:06:01
Message-ID: 4F2BA379.1030807@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 02/03/2012 03:49 AM, Tom Lane wrote:
> Marti Raudsepp<marti(at)juffo(dot)org> writes:
>> We're already seeing first buildfarm failures, on system "narwhal"
>> using an msys/mingw compiler.
> Yeah. After a full day's cycle, the answer seems to be that
> denormalized input works fine everywhere except:
>
> 1. mingw on Windows (even though MSVC builds work)
>
> 2. some Gentoo builds fail (knowing that platform, the phase of the moon
> is probably the most predictable factor determining this).
>
> I'm inclined at this point to remove the regression test cases, because
> we have no principled way to deal with case #2. We could install
> alternative "expected" files that accept the failure, but then what's
> the point of having the test case at all?
>
> It might be worth pressuring the mingw folk to get with the program,
> but I'm not going to be the one to do that.
>
>

No doubt they would tell us to upgrade the compiler. Narwhal's is
horribly old. Neither of my mingw-based members is failing.

cheers

andrew