Re: Fix for Win32 division involving INT_MIN

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Magnus Hagander <mha(at)sollentuna(dot)net>, Wang Haiyong <wanghaiyong(at)neusoft(dot)com>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: Fix for Win32 division involving INT_MIN
Date: 2006-06-12 16:09:12
Message-ID: 200606121609.k5CG9Ci07661@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-patches


Patch applied. Backpatch to 8.1.X.

---------------------------------------------------------------------------

Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > > With no Win32 exception detection code in sight, I propose the following
> > > patch to prevent server crashes for unusual INT_MIN integer division.
> >
> > The overflow code tries hard to avoid assuming it knows what INT_MIN and
> > INT_MAX are --- this is maybe not so important for int4 but it is for
> > int8 (because of our support for int8-less machines). I don't
> > immediately see how to make this test without assuming you know the
> > value of INT_MIN, but we ought to try to come up with one.
> >
> > We do see funny behavior on Intel chips even without Windows, so it'd
> > be better to not #ifdef WIN32 but use the same overflow test for
> > everyone.
>
> > I would imagine the same problem arises with int8, has anyone checked?
>
> Seems int8 is OK on Win32:
>
> postgres=# SELECT (-9223372036854775808) / (-1);
> ERROR: bigint out of range
>
> > Also, the overflow tests in the intNmul routines seem vulnerable.
>
> I reproduced the crash using int4 multiplication. Again int8
> multiplication seemed OK.
>
> I tried int2 and that seemed OK.
>
> Updated patch attached.
>
> --
> Bruce Momjian http://candle.pha.pa.us
> EnterpriseDB http://www.enterprisedb.com
>
> + If your life is a hard drive, Christ can be your backup. +

>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2006-06-12 16:20:07 Re: [BUGS] Bug in window xp
Previous Message Ian Howle 2006-06-12 16:00:57 BUG #2478: PQescapeStringConn

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2006-06-12 16:13:48 Re: Bitmap index AM
Previous Message Tom Lane 2006-06-12 13:47:21 Re: minor fix of elevel in fd.c