Fix for Win32 division involving INT_MIN

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


With no Win32 exception detection code in sight, I propose the following
patch to prevent server crashes for unusual INT_MIN integer division.

One interesting thing is that int4div already has code that a check for
a similar division on all platforms, but _after_ the division, rather
than before.

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

Magnus Hagander wrote:
> Confirmed here.
>
> What we get is Integer Overflow, on the instruction "idiv esi" in postgres!int4div+0x1f. (Per windows debugger.) Same does not happen on Linux.
>
> Tom - hints? ;-) Any idea why this happens on win32 but not linux?
>
> //Magnus
>
> > -----Original Message-----
> > From: pgsql-bugs-owner(at)postgresql(dot)org
> > [mailto:pgsql-bugs-owner(at)postgresql(dot)org] On Behalf Of Wang Haiyong
> > Sent: Wednesday, April 05, 2006 4:34 AM
> > To: pgsql-bugs(at)postgresql(dot)org
> > Subject: [BUGS] Bug in window xp
> >
> > Version(8.1.3)
> > Bug in window xp:
> >
> > C:\Documents and Settings\openbase>pg_ctl start
> > LOG: database system was shut down at 2006-4-04 15:54:43 ??????
> > LOG: checkpoint record is at 0/38C2E0
> > LOG: redo record is at 0/38C2E0; undo record is at 0/0; shutdown TRUE
> > LOG: next transaction ID: 569; next OID: 24576
> > LOG: next MultiXactId: 1; next MultiXactOffset: 0
> > LOG: database system is ready
> > LOG: transaction ID wrap limit is 2147484146, limited by
> > database "postgres"
> >
> > C:\Documents and Settings\openbase>
> > C:\Documents and Settings\openbase>
> > C:\Documents and Settings\openbase>
> > C:\Documents and Settings\openbase>psql
> > Welcome to psql 8.1.3, the PostgreSQL interactive terminal.
> >
> > Type: \copyright for distribution terms
> > \h for help with SQL commands
> > \? for help with psql commands
> > \g or terminate with semicolon to execute query
> > \q to quit
> >
> > openbase=# SELECT (-2147483648) / (-1);
> > LOG: server process (PID 3760) was terminated by signal 21
> > LOG: terminating any other active server processes
> > LOG: all server processes terminated; reinitializing
> > ???????????
> > ???????????????????
> > ???????????????
> > ??????????. ????: LOG: database system was interrupted at
> > 2006-0-05 08:39:56 ??????
> > LOG: checkpoint record is at 0/38C2E0
> > LOG: redo record is at 0/38C2E0; undo record is at 0/0; shutdown TRUE
> > LOG: next transaction ID: 569; next OID: 24576
> > LOG: next MultiXactId: 1; next MultiXactOffset: 0
> > LOG: database system was not properly shut down; automatic
> > recovery in progres
> >
> > FATAL: the database system is starting up
> > ??.
> > !> LOG: record with zero length at 0/38C328
> > LOG: redo is not required
> > LOG: database system is ready
> > LOG: transaction ID wrap limit is 2147484146, limited by
> > database "postgres"
> >
> >
> >
> > ???
> > ???????????
> >
> > ?????????????????????? A1?
> > ???110179
> > ???024?83661905
> > ?????www.neusoft.com
> >
> > ________________________________
> >
> > Confidentiality Notice: The information contained in this
> > e-mail and any accompanying attachment(s) is intended only
> > for the use of the intended recipient and may be confidential
> > and/or privileged of Neusoft Group Ltd., its subsidiaries
> > and/or its affiliates. If any reader of this communication is
> > not the intended recipient, unauthorized use, forwarding,
> > printing, storing, disclosure or copying is strictly
> > prohibited, and may be unlawful. If you have received this
> > communication in error, please immediately notify the sender
> > by return e-mail, and delete the original message and all
> > copies from your system. Thank you.
> > ________________________________
> >
> >
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>

--
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 Content-Type Size
/pgpatches/int_min text/x-diff 784 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2006-06-09 02:18:04 Re: Fix for Win32 division involving INT_MIN
Previous Message Jim C. Nasby 2006-06-08 22:02:28 Re: BUG #2465: Installation

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2006-06-09 02:18:04 Re: Fix for Win32 division involving INT_MIN
Previous Message Alvaro Herrera 2006-06-08 19:35:18 Re: [PATCHES] drop if exists remainder