Opened 2 years ago

Closed 2 years ago

#5173 closed defect (fixed)

st_asflatgeobuf detoast crash

Reported by: robe Owned by: pramsey
Priority: blocker Milestone: PostGIS 3.2.2
Component: postgis Version: 3.2.x
Keywords: Cc:

Description

Noted on postgis dev mailing list: https://lists.osgeo.org/pipermail/postgis-devel/2022-June/029687.html

and patch at

https://lists.osgeo.org/pipermail/postgis-devel/2022-June/029689.html

Hi,

On Sat, Jun 18, 2022 at 06:52:10AM -0500, Justin Pryzby wrote:
> An instance running pg15beta1 crashed while running one of sqlsmith's appalling
> queries.  I reproduced with this, simplified query:
> 
> 	select st_asflatgeobuf(row(1), false, '')
> 	over () from information_schema.table_privileges
> 
> Program terminated with signal 11, Segmentation fault.
> #0  pg_detoast_datum_copy (datum=0x514) at fmgr.c:1719

All versions of st_asflatgeobuf have the same problem, so you can reduce the
reproducer to:

select st_asflatgeobuf(row(1)) from pg_class;

AFAICT, inspect_table() doesn't check that a geometry column was indeed found,
leading to the problem.

Some like that fixes the crash for me:

diff --git a/postgis/flatgeobuf.c b/postgis/flatgeobuf.c
index 1b502e546..545442f31 100644
--- a/postgis/flatgeobuf.c
+++ b/postgis/flatgeobuf.c
@@ -110,6 +110,9 @@ static void inspect_table(struct flatgeobuf_agg_ctx *ctx)
        columns_size++;
    }

+   if (!geom_found)
+       elog(ERROR, "no geom column found");
+
    if (columns_size > 0) {
        ctx->ctx->columns = columns;
        ctx->ctx->columns_size = columns_size;

Attachments (1)

v1-0001-Fix-ST_AsFlatGeobuf-with-rows-that-doesn-t-contai.patch (1.7 KB ) - added by rjuju 2 years ago.

Download all attachments as: .zip

Change History (6)

comment:2 by Paul Ramsey <pramsey@…>, 2 years ago

In 8916302/git:

Error out when asked to build flatgeobuf on table with no geometry (references #5173)

comment:3 by Paul Ramsey <pramsey@…>, 2 years ago

In 18c0a23/git:

Error out when asked to build flatgeobuf on table with no geometry (references #5173)

comment:4 by Paul Ramsey <pramsey@…>, 2 years ago

In 5d23c8a/git:

Error out when asked to build flatgeobuf on table with no geometry (references #5173)

comment:5 by pramsey, 2 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.