Opened 20 months ago

Closed 18 months ago

Last modified 18 months ago

#5241 closed defect (fixed)

ST_SnapToGrid crashes on multipolygon with an empty polygon

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

Description (last modified by robe)

SELECT ST_SnapToGrid(foo1.the_geom, 20.1, 20.1, 20.1, 20.1)  As result
							FROM (
		(SELECT ST_GeomFromText('MULTIPOLYGON (((9 9, 9 1, 1 1, 2 4, 7 7, 9 9)), EMPTY)', 4326) As the_geom ) ) As foo1 LIMIT 10;

I tested this on 3.2.4dev, but assume it crashes on older

Change History (18)

comment:1 by robe, 18 months ago

Description: modified (diff)
Owner: changed from pramsey to robe

comment:2 by robe, 18 months ago

GDB shows the issue is here.

ptarray_grid_in_place (pa=0x7f7f7f7f7f7f7f7e, grid=0x4d1e7c0)
    at ptarray.c:2076
2076            uint32_t ndims = FLAGS_NDIMS(pa->flags);
(gdb) bt
#0  ptarray_grid_in_place (pa=0x7f7f7f7f7f7f7f7e, grid=0x4d1e7c0)
    at ptarray.c:2076
#1  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)

Which is a surprise to me. I can't figure out why it crashes there.

If in the lwgeom_grid_in_place function I add a line

if (lwgeom_is_empty(geom)) return;

It regresses and doesn't crash anymore, and returns expected answer, though I need to test with a smaller grid to confirm.

But I don't know how to protect the ultimate root cause and if that root cause could be hole for other things.

comment:3 by strk, 18 months ago

must be in lwpolygon_grid_in_place

comment:4 by Regina Obe <lr@…>, 18 months ago

In b160678/git:

Fix crash in ST_SnapToGrid on Empties
References #5241 for PostGIS 3.4.0

comment:5 by robe, 18 months ago

Milestone: PostGIS 3.0.8PostGIS 2.5.9

comment:6 by Regina Obe <lr@…>, 18 months ago

In fe13a24/git:

Fix crash in ST_SnapToGrid on Empties
References #5241 for PostGIS 3.3.2

comment:7 by Regina Obe <lr@…>, 18 months ago

In cadb787/git:

Fix crash in ST_SnapToGrid on Empties
References #5241 for PostGIS 3.2.4

comment:8 by Regina Obe <lr@…>, 18 months ago

In 7d0282b/git:

Fix crash in ST_SnapToGrid on Empties
References #5241 for PostGIS 3.1.8

comment:9 by Regina Obe <lr@…>, 18 months ago

In 54071ee/git:

Fix crash in ST_SnapToGrid on Empties
References #5241 for PostGIS 3.0.8

comment:10 by Regina Obe <lr@…>, 18 months ago

In 142b759/git:

Fix crash in ST_SnapToGrid on Empties
References #5241 for PostGIS 2.5.9

comment:11 by robe, 18 months ago

Okay looks like berrie64 prefers to round the numbers thus disagreeing with the answer for the new test

10:46:09  ./regress/core/snaptogrid .. failed (diff expected obtained: /tmp/pgis_reg/test_72_diff)
10:46:09 -----------------------------------------------------------------------------
10:46:09 --- ./regress/core/snaptogrid_expected	2022-10-29 08:36:23.540007775 -0600
10:46:09 +++ /tmp/pgis_reg/test_72_out	2022-10-29 08:46:09.107263583 -0600
10:46:09 @@ -6,4 +6,4 @@
10:46:09  POLYGON((0 0,10 0,10 10,0 10,0 0))|BOX(0 0,10 10)
10:46:09  POLYGON((0 0,10 0,10 10,0 10,0 0))|BOX(0 0,10 10)
10:46:09  #5241|MULTIPOLYGON EMPTY
10:46:09 -#5241|MULTIPOLYGON(((9 9,9 1,1 1,2 4,7.000000000000001 7.000000000000001,9 9)))
10:46:09 +#5241|MULTIPOLYGON(((9 9,9 1,1 1,2 4,7 7,9 9)))
10:46:09 -----------------------------------------------------------------------------

Need to revise to round the output so all bots agree. Why berrie isn't having the same issue seems odd.

comment:12 by Regina Obe <lr@…>, 18 months ago

In d745b7b9/git:

Change test so also agrees on Arm.
References #5241 for PostGIS 2.5.9

comment:13 by Regina Obe <lr@…>, 18 months ago

In f94d56c/git:

Change test so also agrees on Arm.
References #5241 for PostGIS 3.4.0

comment:14 by Regina Obe <lr@…>, 18 months ago

In 0e8ff74/git:

Change test so also agrees on Arm.
References #5241 for PostGIS 3.3.2

comment:15 by Regina Obe <lr@…>, 18 months ago

In 92ec0fa6/git:

Change test so also agrees on Arm.
References #5241 for PostGIS 3.2.4

comment:16 by Regina Obe <lr@…>, 18 months ago

Resolution: fixed
Status: newclosed

In 1969e1e/git:

  1. Change test so also agrees on Arm.
  2. Add to NEWS

Closes #5241 for PostGIS 3.1.8

comment:17 by Regina Obe <lr@…>, 18 months ago

In d8dcd70/git:

Add missing notes, references #5241 for PostGIS 3.1.8

comment:18 by Regina Obe <lr@…>, 18 months ago

In 1010c7a/git:

Change test so also agrees on Arm.
References #5241 for PostGIS 3.0.8

Note: See TracTickets for help on using tickets.