Skip site navigation (1) Skip section navigation (2)

Re: Fix for Win32 division involving INT_MIN

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: 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-09 02:40:30
Message-ID: 200606090240.k592eUj23952@candle.pha.pa.us (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-bugspgsql-patches
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. +

Attachment: /pgpatches/int_min
Description: text/x-diff (1.2 KB)

In response to

Responses

pgsql-bugs by date

Next:From: kah_hang_angDate: 2006-06-09 09:29:08
Subject: Re: statement stuck when the connection grew up to 45 or more
Previous:From: Tom LaneDate: 2006-06-09 02:18:04
Subject: Re: Fix for Win32 division involving INT_MIN

pgsql-patches by date

Next:From: Dhanaraj MDate: 2006-06-09 05:35:03
Subject: Re: Patch for - Allow server logs to be remotely read
Previous:From: Tom LaneDate: 2006-06-09 02:18:04
Subject: Re: Fix for Win32 division involving INT_MIN

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group