Re: Server Crash into contrib module ISN into 64bit OS

Lists: pgsql-hackers
From: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Server Crash into contrib module ISN into 64bit OS
Date: 2008-11-28 12:19:35
Message-ID: 460abcb10811280419n2cdef3aeje04f04d543fc110f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Following test end up with the server crash into 8.4 cvs Head.

uname -a
Linux localhost.localdomain 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT
2007 x86_64 x86_64 x86_64 GNU/Linux

Testcase with ISN contrib module:
=========================

CREATE OR REPLACE function isbn_issn_proc() returns void as
$$
declare
v1 isbn;
BEGIN
v1 := isbn_in('0-596-00270-x');
END;
$$ LANGUAGE plpgsql;

select isbn_issn_proc();

Analysis:
=======

Found that we are getting crash while doing the memcpy into datumCopy().

Datum
datumCopy(Datum value, bool typByVal, int typLen)
{
...
if (DatumGetPointer(value) == NULL)
return PointerGetDatum(NULL);

realSize = datumGetSize(value, typByVal, typLen);

s = (char *) palloc(realSize);
memcpy(s, DatumGetPointer(value), realSize); /* crash */
}

Actually we get crash while doing the DatumGetPointer(), upon further
investigation found that in isbn_in() function we are using
PG_RETURN_EAN13(), which seems to be returning the wrong address in case of
64bit OS.

I was wondering that why its happening in PG 8.4; then found that we are
having USE_FLOAT8_BYVAL into current version, because of the same not
getting correct/expected Datum representation of the int64.

postgres.h

#ifdef USE_FLOAT8_BYVAL
#define Int64GetDatum(X) ((Datum) SET_8_BYTES(X))
#else
extern Datum Int64GetDatum(int64 X);
#endif

When I tried the same case with --disable-float8-byval option, test running
as expected.

Regards,
Rushabh Lathia

www.EnterpriseDB.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Server Crash into contrib module ISN into 64bit OS
Date: 2008-11-28 16:59:12
Message-ID: 27117.1227891552@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com> writes:
> Following test end up with the server crash into 8.4 cvs Head.

Hmm, this'd have been noticed sooner if contrib/isn had even
minimal regression tests :-( Anyone feel like writing some?

regards, tom lane


From: "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Cc: rushabh(dot)lathia(at)enterprisedb(dot)com
Subject: Re: Server Crash into contrib module ISN into 64bit OS
Date: 2008-12-01 05:21:40
Message-ID: 460abcb10811302121t4183f735hd32df118d2faef94@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I think we need to create ISBN type ( contrib/isn/isn.sql.in) with flag
PASSBYVALUE flag when flag USE_FLOAT8_BYVAL is set.

-Regards,
Rushabh

On Fri, Nov 28, 2008 at 10:29 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> "Rushabh Lathia" <rushabh(dot)lathia(at)gmail(dot)com> writes:
> > Following test end up with the server crash into 8.4 cvs Head.
>
> Hmm, this'd have been noticed sooner if contrib/isn had even
> minimal regression tests :-( Anyone feel like writing some?
>
> regards, tom lane
>

--
Rushabh Lathia