Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#4894 closed defect (fixed)

Intersection with distinct geometries crashes postgres

Reported by: mschott Owned by: pramsey
Priority: medium Milestone: PostGIS 3.1.2
Component: postgis Version: 3.1.x
Keywords: Cc:

Description

A set of geometries were extracted from OSM and a raster. They were cleaned (st_makevalid) and snapped to a 7 digit grid. The OSM polygons are collected into a geometrycollection (group by) and intersected with the raster polygons.

The following combination of geometries crashes postgres (commands that crash postgres are commented out):

WITH geoms AS (
    SELECT
        st_geomfromtext('GEOMETRYCOLLECTION (MULTIPOLYGON (((13.0495147 52.41036419999999, 13.0494857 52.41024449999999, 13.048656099999999 52.409416799999995, 13.0479896 52.40870139999999, 13.047915600000001 52.4086247, 13.047459499999999 52.40815189999999, 13.046588400000001 52.40738379999999, 13.045684800000002 52.40768049999999, 13.0456071 52.407692699999984, 13.045425800000002 52.407721200000005, 13.045244700000001 52.40774959999999, 13.044752299999999 52.407786599999994, 13.044569300000001 52.40780169999999, 13.0439619 52.40786429999999, 13.043509 52.40795669999999, 13.043333899999999 52.40800399999999, 13.0431124 52.40809480000001, 13.042738300000002 52.40826519999999, 13.042455400000001 52.4083951, 13.0422325 52.408509099999996, 13.042517799999999 52.40876749999999, 13.0440662 52.41139409999999, 13.0495147 52.41036419999999))))') AS a,
        st_geomfromtext('POLYGON ((13.0444661 52.4111012, 13.044466100000001 52.41110079999999, 13.044466799999999 52.41110079999999, 13.0444669 52.41110039999999, 13.044467599999999 52.41110039999999, 13.044467599999999 52.4111013, 13.0444661 52.4111012))') AS b
)
SELECT
st_isvalid(a),
st_isvalid(b)
--,st_intersects(a,b)
--,st_intersection(a,b)
 --,st_difference(a,b)
FROM
    geoms;

Any other geometry combination I have tried so far works except for this combination.

Version:

POSTGIS="3.1.1 0" [EXTENSION] PGSQL="130" GEOS="3.8.1-CAPI-1.13.3" PROJ="7.1.1" GDAL="GDAL 3.1.4, released 2020/10/20" LIBXML="2.9.10" LIBJSON="0.15" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)" (core procs from "3.1.1 aaf4c79" need upgrade) TOPOLOGY (topology procs from "3.1.1 aaf4c79" need upgrade) RASTER (raster procs from "3.1.1 aaf4c79" need upgrade)

PostgreSQL 13.2 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.2.1_pre1) 10.2.1 20201203, 64-bit

LOG message:

.278 UTC [1] LOG:  server process (PID 2091) was terminated by signal 11: Segmentation fault
.278 UTC [1] DETAIL:  Failed process was running: WITH geoms AS (
ESC[36midealvgi_postgisdb |ESC[0m           SELECT
ESC[36midealvgi_postgisdb |ESC[0m               st_geomfromtext('GEOMETRYCOLLECTION (MULTIPOLYGON (((13.0495147 52.41036419999999, 13.0494857 52.41024449999999, 13.048656099999999 52.409416799999995, 13.0479896 52.40870139999999, 13.047915600000001 52.4086247, 13.047459499999999 52.40815189999999, 13.046588400000001 52.40738379999999, 13.045684800000002 52.40768049999999, 13.0456071 52.407692699999984, 13.045425800000002 52.407721200000005, 13.045244700000001 52.40774959999999, 13.044752299999999 52.407786599999994, 13.044569300000001 52.40780169999999, 13.0439619 52.40786429999999, 13.043509 52.40795669999999, 13.043333899999999 52.40800399999999, 13.0431124 52.40809480000001, 13.042738300000002 52.40826519999999, 13.042455400000001 52.4083951, 13.0422325 52.408509099999996, 13.042517799999999 52.40876749999999, 13.0440662 52.41139409999999, 13.0495147 52.41036419999999))))') AS a,
ESC[36midealvgi_postgisdb |ESC[0m               st_geomfromtext('POLYGON ((13.0444661 52.4111012, 13.044466100000001 52.41110079999999, 13.044466799999999 52.41110079999999, 13.044
.279 UTC [1] LOG:  terminating any other active server processes
.279 UTC [2046] WARNING:  terminating connection because of crash of another server process
.279 UTC [2046] DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
.279 UTC [2046] HINT:  In a moment you should be able to reconnect to the database and repeat your command.
.279 UTC [2101] WARNING:  terminating connection because of crash of another server process
.279 UTC [2101] DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
.279 UTC [2101] HINT:  In a moment you should be able to reconnect to the database and repeat your command.
.280 UTC [2102] WARNING:  terminating connection because of crash of another server process
.280 UTC [2102] DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
.280 UTC [2102] HINT:  In a moment you should be able to reconnect to the database and repeat your command.
.281 UTC [1] LOG:  all server processes terminated; reinitializing
.293 UTC [2103] LOG:  database system was interrupted; last known up at 2021-04-09 12:55:01 UTC
.332 UTC [2104] FATAL:  the database system is in recovery mode
.369 UTC [2103] LOG:  database system was not properly shut down; automatic recovery in progress
.373 UTC [2103] LOG:  invalid record length at 1/1A694510: wanted 24, got 0
.373 UTC [2103] LOG:  redo is not required
.385 UTC [2105] FATAL:  the database system is in recovery mode
.415 UTC [1] LOG:  database system is ready to accept connections

Change History (4)

comment:1 by mdavis, 3 years ago

This is caused by a GEOS 3.8 issue (see GEOS-1047). This is fixed in the 3.8 branch, but not yet released. A release of GEOS 3.8.2 is underway.

In the meantime, a workaround is to convert the single-element GEOMETRYCOLLECTION/MULTIPOLYGON to a POLYGON. This can be done using ST_CollectionHomogenize.

comment:2 by mdavis, 3 years ago

GEOS 3.8.2 is now released, with a fix for this bug (and quite a few others).

comment:3 by pramsey, 3 years ago

Resolution: fixed
Status: newclosed

comment:4 by mschott, 3 years ago

Great, contrats to this great community. I will try it once the new version is available in my archlinux-docker.

Note: See TracTickets for help on using tickets.