Re: BUG #15781: subselect on foreign table (postgres_fdw) can crash (segfault)

From: Sergei Kornilov <sk(at)zsrv(dot)org>
To: "sean(dot)johnston(at)edgeintelligence(dot)com" <sean(dot)johnston(at)edgeintelligence(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #15781: subselect on foreign table (postgres_fdw) can crash (segfault)
Date: 2019-04-25 14:20:17
Message-ID: 54257121556202017@sas1-46c84f197234.qloud-c.yandex.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Hi

I can reproduce this on REL_11_STABLE and HEAD.

Here is backtrace from REL_11_STABLE:

#0 CheckVarSlotCompatibility (slot=slot(at)entry=0x0, attnum=1, vartype=16) at execExprInterp.c:1867
#1 0x00005611db3cb342 in CheckExprStillValid (state=state(at)entry=0x5611dd0fa368, econtext=econtext(at)entry=0x5611dd0f9730) at execExprInterp.c:1831
#2 0x00005611db3cb36e in ExecInterpExprStillValid (state=0x5611dd0fa368, econtext=0x5611dd0f9730, isNull=0x7ffc524ca89f) at execExprInterp.c:1780
#3 0x00007fc3648bac8d in ExecEvalExpr (isNull=0x7ffc524ca89f, econtext=0x5611dd0f9730, state=<optimized out>)
at ../../src/include/executor/executor.h:294
#4 process_query_params (econtext=0x5611dd0f9730, param_flinfo=0x5611dd0fa2d0, param_exprs=<optimized out>,
param_values=param_values(at)entry=0x5611dd0fad50) at postgres_fdw.c:4124
#5 0x00007fc3648baf82 in create_cursor (node=<optimized out>) at postgres_fdw.c:3148
#6 0x00007fc3648bb041 in postgresIterateForeignScan (node=0x5611dd0f9618) at postgres_fdw.c:1451
#7 0x00005611db4026c4 in ForeignNext (node=node(at)entry=0x5611dd0f9618) at nodeForeignscan.c:54
#8 0x00005611db3db4ff in ExecScanFetch (recheckMtd=0x5611db40256e <ForeignRecheck>, accessMtd=0x5611db402650 <ForeignNext>, node=0x5611dd0f9618)
at execScan.c:95
#9 ExecScan (node=0x5611dd0f9618, accessMtd=accessMtd(at)entry=0x5611db402650 <ForeignNext>,
recheckMtd=recheckMtd(at)entry=0x5611db40256e <ForeignRecheck>) at execScan.c:145
#10 0x00005611db40254d in ExecForeignScan (pstate=<optimized out>) at nodeForeignscan.c:121
#11 0x00005611db3d9aa2 in ExecProcNodeFirst (node=0x5611dd0f9618) at execProcnode.c:445
#12 0x00005611db3d2039 in ExecProcNode (node=0x5611dd0f9618) at ../../../src/include/executor/executor.h:247
#13 ExecutePlan (estate=estate(at)entry=0x5611dd0b2718, planstate=0x5611dd0f9618, use_parallel_mode=<optimized out>,
operation=operation(at)entry=CMD_SELECT, sendTuples=sendTuples(at)entry=true, numberTuples=numberTuples(at)entry=0, direction=ForwardScanDirection,
dest=0x5611dd0df520, execute_once=true) at execMain.c:1723
#14 0x00005611db3d2c94 in standard_ExecutorRun (queryDesc=0x5611dd0c7be8, direction=ForwardScanDirection, count=0, execute_once=<optimized out>)
at execMain.c:364
#15 0x00005611db3d2d4f in ExecutorRun (queryDesc=queryDesc(at)entry=0x5611dd0c7be8, direction=direction(at)entry=ForwardScanDirection,
count=count(at)entry=0, execute_once=<optimized out>) at execMain.c:307
#16 0x00005611db53f0ed in PortalRunSelect (portal=portal(at)entry=0x5611dd054278, forward=forward(at)entry=true, count=0,
count(at)entry=9223372036854775807, dest=dest(at)entry=0x5611dd0df520) at pquery.c:932
#17 0x00005611db5407de in PortalRun (portal=portal(at)entry=0x5611dd054278, count=count(at)entry=9223372036854775807, isTopLevel=isTopLevel(at)entry=true,
run_once=run_once(at)entry=true, dest=dest(at)entry=0x5611dd0df520, altdest=altdest(at)entry=0x5611dd0df520, completionTag=0x7ffc524cad10 "")
at pquery.c:773
#18 0x00005611db53caa9 in exec_simple_query (
query_string=query_string(at)entry=0x5611dcfedac8 "select exists(select c1 from ft4), avg(c1) from ft4 where c1 = (select\nmax(c1) from ft4);")
at postgres.c:1145
#19 0x00005611db53e9ce in PostgresMain (argc=<optimized out>, argv=argv(at)entry=0x5611dd018910, dbname=<optimized out>, username=<optimized out>)
at postgres.c:4182
#20 0x00005611db4b8d8b in BackendRun (port=port(at)entry=0x5611dd0115a0) at postmaster.c:4358
#21 0x00005611db4bbd2f in BackendStartup (port=port(at)entry=0x5611dd0115a0) at postmaster.c:4030
#22 0x00005611db4bbf52 in ServerLoop () at postmaster.c:1707
#23 0x00005611db4bd459 in PostmasterMain (argc=3, argv=<optimized out>) at postmaster.c:1380
#24 0x00005611db4210c9 in main (argc=3, argv=0x5611dcfe81f0) at main.c:228

Similar from HEAD:

#0 CheckVarSlotCompatibility (slot=slot(at)entry=0x0, attnum=1, vartype=16) at execExprInterp.c:1850
#1 0x00005581fa6011b7 in CheckExprStillValid (state=state(at)entry=0x5581fba700c0, econtext=econtext(at)entry=0x5581fba6f4f0) at execExprInterp.c:1814
#2 0x00005581fa6011e3 in ExecInterpExprStillValid (state=0x5581fba700c0, econtext=0x5581fba6f4f0, isNull=0x7ffcad499ebf) at execExprInterp.c:1763
#3 0x00007f276130d67c in ExecEvalExpr (isNull=0x7ffcad499ebf, econtext=0x5581fba6f4f0, state=<optimized out>)
at ../../src/include/executor/executor.h:288
#4 process_query_params (econtext=0x5581fba6f4f0, param_flinfo=0x5581fba70028, param_exprs=<optimized out>,
param_values=param_values(at)entry=0x5581fba70aa8) at postgres_fdw.c:4307
#5 0x00007f276130d982 in create_cursor (node=<optimized out>) at postgres_fdw.c:3247
#6 0x00007f276130da3c in postgresIterateForeignScan (node=0x5581fba6f3d8) at postgres_fdw.c:1517
#7 0x00005581fa63adad in ForeignNext (node=node(at)entry=0x5581fba6f3d8) at nodeForeignscan.c:54
#8 0x00005581fa61104b in ExecScanFetch (recheckMtd=0x5581fa63adf1 <ForeignRecheck>, accessMtd=0x5581fa63ad2c <ForeignNext>, node=0x5581fba6f3d8)
at execScan.c:93
#9 ExecScan (node=0x5581fba6f3d8, accessMtd=accessMtd(at)entry=0x5581fa63ad2c <ForeignNext>,
recheckMtd=recheckMtd(at)entry=0x5581fa63adf1 <ForeignRecheck>) at execScan.c:143
#10 0x00005581fa63add0 in ExecForeignScan (pstate=<optimized out>) at nodeForeignscan.c:115
#11 0x00005581fa60f3e8 in ExecProcNodeFirst (node=0x5581fba6f3d8) at execProcnode.c:445
#12 0x00005581fa607fdd in ExecProcNode (node=0x5581fba6f3d8) at ../../../src/include/executor/executor.h:239
#13 ExecutePlan (estate=estate(at)entry=0x5581fba2abb8, planstate=0x5581fba6f3d8, use_parallel_mode=<optimized out>,
operation=operation(at)entry=CMD_SELECT, sendTuples=sendTuples(at)entry=true, numberTuples=numberTuples(at)entry=0, direction=ForwardScanDirection,
dest=0x5581fba5cac0, execute_once=true) at execMain.c:1648
#14 0x00005581fa608c2a in standard_ExecutorRun (queryDesc=0x5581fba207f8, direction=ForwardScanDirection, count=0, execute_once=<optimized out>)
at execMain.c:365
#15 0x00005581fa608ce5 in ExecutorRun (queryDesc=queryDesc(at)entry=0x5581fba207f8, direction=direction(at)entry=ForwardScanDirection,
count=count(at)entry=0, execute_once=<optimized out>) at execMain.c:309
#16 0x00005581fa782d65 in PortalRunSelect (portal=portal(at)entry=0x5581fb9bb168, forward=forward(at)entry=true, count=0,
count(at)entry=9223372036854775807, dest=dest(at)entry=0x5581fba5cac0) at pquery.c:929
#17 0x00005581fa78442c in PortalRun (portal=portal(at)entry=0x5581fb9bb168, count=count(at)entry=9223372036854775807, isTopLevel=isTopLevel(at)entry=true,
run_once=run_once(at)entry=true, dest=dest(at)entry=0x5581fba5cac0, altdest=altdest(at)entry=0x5581fba5cac0, completionTag=0x7ffcad49a330 "")
at pquery.c:770
#18 0x00005581fa780755 in exec_simple_query (
query_string=query_string(at)entry=0x5581fb955ac8 "select exists(select c1 from ft4), avg(c1) from ft4 where c1 = (select\nmax(c1) from ft4);")
at postgres.c:1215
#19 0x00005581fa78263d in PostgresMain (argc=<optimized out>, argv=argv(at)entry=0x5581fb981310, dbname=<optimized out>, username=<optimized out>)
at postgres.c:4249
#20 0x00005581fa6f7979 in BackendRun (port=port(at)entry=0x5581fb978d20) at postmaster.c:4426
#21 0x00005581fa6faa98 in BackendStartup (port=port(at)entry=0x5581fb978d20) at postmaster.c:4117
#22 0x00005581fa6facbb in ServerLoop () at postmaster.c:1704
#23 0x00005581fa6fc1fc in PostmasterMain (argc=3, argv=<optimized out>) at postmaster.c:1377
#24 0x00005581fa65acf1 in main (argc=3, argv=0x5581fb9501f0) at main.c:228

regards, Sergei

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Amit Langote 2019-04-25 14:45:53 Re: BUG #15672: PostgreSQL 11.1/11.2 crashed after dropping a partition table
Previous Message Francisco Olarte 2019-04-25 14:03:24 Re: bug: evil autoConcat when each string is on new line

Browse pgsql-hackers by date

  From Date Subject
Next Message Laurenz Albe 2019-04-25 14:29:08 Re: pgsql: Allow insert and update tuple routing and COPY for foreign table
Previous Message Tom Lane 2019-04-25 13:49:22 Re: [Patch] Check file type before calling AllocateFile() for files out of pg data directory to avoid potential issues (e.g. hang).