Opened 5 months ago

Closed 5 months ago

#5627 closed defect (fixed)

Empty crashes ST_Intersects

Reported by: wenjing Owned by: pramsey
Priority: critical Milestone: PostGIS 3.0.11
Component: postgis Version: 3.4.x
Keywords: Cc:


The following statement crashes PostGIS:

CREATE TABLE t (id int, geom geometry);
INSERT INTO t (id, geom) VALUES (1,ST_GeomFromText('MULTIPOLYGON(((-357 477,-392 574,-378 574,-357 477)))'));
INSERT INTO t (id, geom) VALUES (2,ST_GeomFromText('MULTIPOINT(EMPTY,(-378 574),(-357 477))'));
SELECT COUNT(*) FROM t As a1 , t As a2 WHERE ST_Intersects(a1.geom, a2.geom) and <>;
-- psql:script/simplify.sql:32: NOTICE:  lwgeom_api.c [352] called with n=0 and npoints=0
-- psql:script/simplify.sql:32: server closed the connection unexpectedly
--         This probably means the server terminated abnormally
--         before or while processing the request.
-- psql:script/simplify.sql:32: error: connection to server was lost

The stack information:

#0  0x00007fa09c479141 in point_in_ring_rtree (root=0x55ea670db450, point=0x0) at lwgeom_rtree.c:515
#1  0x00007fa09c4793c4 in point_in_multipolygon_rtree (root=0x55ea670db1d8, polyCount=1, 
    ringCounts=0x55ea670db1c8, point=0x55ea66d521c8) at lwgeom_rtree.c:602
#2  0x00007fa09c4794df in pip_short_circuit (poly_cache=0x55ea670db1a0, point=0x55ea66d521c8, 
    gpoly=0x55ea66d520f0) at lwgeom_rtree.c:658
#3  0x00007fa09c464787 in ST_Intersects (fcinfo=0x55ea670d8d30) at lwgeom_geos.c:2382
#4  0x000055ea65d530b0 in ExecInterpExpr ()
#5  0x000055ea65d839bc in ExecNestLoop ()
#6  0x000055ea65d662b1 in fetch_input_tuple ()
#7  0x000055ea65d693b3 in ExecAgg ()
#8  0x000055ea65d568e2 in standard_ExecutorRun ()
#9  0x000055ea65ef201f in PortalRunSelect ()
#10 0x000055ea65ef3403 in PortalRun ()
#11 0x000055ea65eef8dd in exec_simple_query ()
#12 0x000055ea65ef1c25 in PostgresMain ()
#13 0x000055ea65e6bdbe in ServerLoop ()
#14 0x000055ea65e6cd0c in PostmasterMain ()
#15 0x000055ea65bbeba1 in main ()

The version is the newest on GitHub:

POSTGIS="3.5.0dev 3.4.0rc1-818-g6c2e935b6" [EXTENSION] PGSQL="170" GEOS="3.13.0dev-CAPI-1.18.0" PROJ="8.2.1
share/proj/proj.db" LIBXML="2.9.13"

Change History (6)

comment:1 by robe, 5 months ago

Milestone: PostGIS 3.4.2PostGIS 3.0.11

comment:2 by robe, 5 months ago

I confirm I get the same issue in GEOS 3.13 and GEOS 3.12.2dev

comment:3 by robe, 5 months ago

I should add the error can't be triggered by a simple

SELECT ST_Intersects(ST_GeomFromText('MULTIPOLYGON(((-357 477,-392 574,-378 574,-357 477)))'), ST_GeomFromText('MULTIPOINT(EMPTY,(-378 574),(-357 477))'));

So I'm guessing issue is a PostGIS one and not GEOS

comment:4 by pramsey, 5 months ago

Simpler reproducer. It is certainly the cache calculation.

WITH geoms AS (
	'MULTIPOLYGON(((-357 477,-392 574,-378 574,-357 477)))'::geometry,
	'MULTIPOLYGON(((-357 477,-392 574,-378 574,-357 477)))'::geometry
	]) AS geom
SELECT ST_Intersects(
	'MULTIPOINT(EMPTY,(-378 574))'::geometry,
FROM geoms;

comment:5 by Paul Ramsey <pramsey@…>, 5 months ago

In e85cd105/git:

Handle EMPTY member of collections in PIP cache, references #5627

comment:6 by pramsey, 5 months ago

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