dbTalk Databases Forums  

Re: [BUGS] [GENERAL] contrib module intagg crashing the backend

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] [GENERAL] contrib module intagg crashing the backend in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael Fuhr
 
Posts: n/a

Default Re: [BUGS] [GENERAL] contrib module intagg crashing the backend - 03-22-2005 , 09:58 PM






On Tue, Mar 22, 2005 at 05:21:32PM -0800, Ron Mayer wrote:
Quote:
If one of the contrib modules (int_array_aggregate in contrib/intagg) is
crashing my backend, where's a good place to report a bug or get hints
where to look further?
Bug reports should go to the pgsql-bugs mailing list (I've cc'd it
on this message). Searching the list archives for similar problems
can be helpful.

If the backend crashed then there might be a core dump somewhere
under the $PGDATA directory. Using a debugger like gdb to get a
stack trace from the core dump can help pinpoint the problem.

Quote:
It seems to work fine on small arrays, but crashes on large ones.
The second query would have put about 500 rows in the aggregate.
I can duplicate the crash in 8.0.1 (REL8_0_STABLE) with the following
(512 works, 513 crashes):

CREATE TABLE foo (id integer, name text);
INSERT INTO foo (id, name)
SELECT x, 'test' FROM generate_series(1, 513) AS g(x);
SELECT name, int_array_aggregate(id) FROM foo GROUP BY name;

Here's a partial stack trace:

#0 0x81e003b in pfree (pointer=0x839f130) at mcxt.c:583
#1 0x810d044 in advance_transition_function (aggstate=0x839d188, peraggstate=0x839d908,
pergroupstate=0x83a1aa0, newVal=513, isNull=0 '\000') at nodeAgg.c:395
#2 0x810d0f4 in advance_aggregates (aggstate=0x839d188, pergroup=0x83a1aa0) at nodeAgg.c:439
#3 0x810d782 in agg_fill_hash_table (aggstate=0x839d188) at nodeAgg.c:935
#4 0x810d448 in ExecAgg (node=0x839d188) at nodeAgg.c:674

Line 583 in mcxt.c is:

(*header->context->methods->free_p) (header->context, pointer);

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org


Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] [GENERAL] contrib module intagg crashing the backend - 03-22-2005 , 11:13 PM






Michael Fuhr <mike (AT) fuhr (DOT) org> writes:
Quote:
I can duplicate the crash in 8.0.1 (REL8_0_STABLE) with the following
Grumble ... I seem to have managed to promote intagg from
broken-on-64bit-platforms to broken-on-every-platform ...
will look into a fix tomorrow.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
  #3  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] [GENERAL] contrib module intagg crashing the backend - 03-23-2005 , 12:38 PM



I wrote:
Quote:
Grumble ... I seem to have managed to promote intagg from
broken-on-64bit-platforms to broken-on-every-platform ...
will look into a fix tomorrow.
Ron's problem is essentially a double-free bug. In this patch:

2005-01-27 16:35 tgl

* contrib/intagg/: int_aggregate.c, int_aggregate.sql.in
(REL7_3_STABLE), int_aggregate.c, int_aggregate.sql.in
(REL7_4_STABLE), int_aggregate.c, int_aggregate.sql.in
(REL8_0_STABLE), int_aggregate.c, int_aggregate.sql.in: Fix
security and 64-bit issues in contrib/intagg. This code could
stand to be rewritten altogether, but for now just stick a finger
in the dike.

I modified intagg to declare its transition data type as int4[] (which
is what it really is) rather than int4. Unfortunately that means that
nodeAgg.c is now aware that the transition value is pass-by-reference,
and so it thinks it needs to manage the memory used for it; which
intagg.c is also trying to do; so they both free the same bit of memory.

There is already a "proper" fix for this problem in CVS tip, but it's
too invasive to consider back-patching; not least because nodeAgg's
memory management strategy has changed since 7.3 and the fix would
probably not work that far back.

What I'm thinking I have to do is revert intagg in the back branches to
lie about its transition data type, but still have it pull the pointer
out of the passed Datum with DatumGetPointer (as opposed to the old,
definitely 64-bit-broken method of DatumGetInt32 and then cast to pointer).
This should work because nodeAgg doesn't inquire into the actual
contents of any Datum it doesn't think is pass-by-reference; so it will
never discard the upper bits of the pointer.

Ugh. Glad we have a cleaner solution to go forward with.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.