Server Crash into contrib module ISN into 64bit OS

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
Thread:
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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2008-11-28 13:08:12 Re: HEAD build failure on win32 mingw
Previous Message Peter Eisentraut 2008-11-28 11:46:40 Re: Distinct types