[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 3.0.1-24-gaeea512

git at osgeo.org git at osgeo.org
Mon Jun 29 02:28:27 PDT 2020


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, stable-3.0 has been updated
       via  aeea5121b2a99137e67ea4177c8b5d43efcba35d (commit)
       via  273b7eaad3e9a6dfae8eef9e29f78dd67582a4ca (commit)
       via  037eba580cc6de9b4a2bc5c4777bb081bad401f1 (commit)
      from  c76d1b1178065e5f540b848bb37cfa43dcb61982 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit aeea5121b2a99137e67ea4177c8b5d43efcba35d
Author: Sandro Santilli <strk at kbt.io>
Date:   Mon Jun 29 11:17:41 2020 +0200

    Update NEWS file

diff --git a/NEWS b/NEWS
index f97f0bf..1964cbe 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ PostGIS 3.0.2
 2020/XX/XX
 
 * Bug Fixes and Enhancements *
+  - #4709, Fix crash in adding edge to corrupted topology, (Sandro Santilli)
+  - Handle non-closed edge rings by human readable error (Sandro Santilli)
   - #4706, Fix crash in ST_ChangeEdgeGeom on corrupted topology (Sandro Santilli)
   - #4652, Fix several memory related bugs in ST_GeomFromGML (Raúl Marín)
   - #4661, Fix access to spatial_ref_sys with a non default schema (Raúl Marín)

commit 273b7eaad3e9a6dfae8eef9e29f78dd67582a4ca
Author: Sandro Santilli <strk at kbt.io>
Date:   Fri Jun 26 17:07:24 2020 +0200

    Handle non-closed edge rings by human readable error
    
    Handle both topological and geometrical corruption
    Have getRingEdges raise an error if topology is corrupted
    
    Includes test.
    
    References #4709 in 3.0 branch

diff --git a/liblwgeom/lwgeom_topo.c b/liblwgeom/lwgeom_topo.c
index f140d8f..652f7da 100644
--- a/liblwgeom/lwgeom_topo.c
+++ b/liblwgeom/lwgeom_topo.c
@@ -1898,6 +1898,14 @@ _lwt_AddFaceSplit( LWT_TOPOLOGY* topo,
     return -2;
   }
   const POINTARRAY *pa = shell->rings[0];
+  if ( ! ptarray_is_closed(pa) )
+  {
+    lwpoly_free(shell);
+    lwfree( signed_edge_ids );
+    lwerror("Corrupted topology: ring of edge %" LWTFMT_ELEMID
+            " is geometrically not-closed", sedge);
+    return -2;
+  }
 
   int isccw = ptarray_isccw(pa);
   LWDEBUGF(1, "Ring of edge %" LWTFMT_ELEMID " is %sclockwise",
diff --git a/topology/postgis_topology.c b/topology/postgis_topology.c
index a5d3b0c..2a7e851 100644
--- a/topology/postgis_topology.c
+++ b/topology/postgis_topology.c
@@ -1241,6 +1241,40 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY *topo, LWT_ELEMID edge, uint64_t *numelems
     val = DatumGetInt32(dat);
     edges[i] = val;
     POSTGIS_DEBUGF(1, "Component " UINT64_FORMAT " in ring of edge %" LWTFMT_ELEMID " is edge %d", i, edge, val);
+
+    /* For the last entry, check that we returned back to start
+     * point, or complain about topology being corrupted */
+    if ( i == *numelems - 1 )
+    {
+      int32 nextedge;
+      int sidecol = val > 0 ? 3 : 4;
+      const char *sidetext = val > 0 ? "left" : "right";
+
+      dat = SPI_getbinval(row, rowdesc, sidecol, &isnull);
+      if ( isnull )
+      {
+        lwfree(edges);
+        cberror(topo->be_data, "Edge %d" /*LWTFMT_ELEMID*/
+                               " has NULL next_%s_edge",
+                               val, sidetext);
+        *numelems = UINT64_MAX;
+        return NULL;
+      }
+      nextedge = DatumGetInt32(dat);
+      POSTGIS_DEBUGF(1, "Last component in ring of edge %"
+                        LWTFMT_ELEMID " (%" LWTFMT_ELEMID ") has next_%s_edge %d",
+                        edge, val, sidetext, nextedge);
+      if ( nextedge != edge )
+      {
+        lwfree(edges);
+        cberror(topo->be_data, "Corrupted topology: ring of edge %"
+                               LWTFMT_ELEMID " is topologically non-closed",
+                               edge);
+        *numelems = UINT64_MAX;
+        return NULL;
+      }
+    }
+
   }
 
   SPI_freetuptable(SPI_tuptable);
diff --git a/topology/test/regress/st_addedgemodface.sql b/topology/test/regress/st_addedgemodface.sql
index 3791480..2939c22 100644
--- a/topology/test/regress/st_addedgemodface.sql
+++ b/topology/test/regress/st_addedgemodface.sql
@@ -520,6 +520,22 @@ SELECT f.id, r.element_type||':'||r.element_id as comp
 
 SELECT 'F'||face_id, st_astext(mbr) FROM city_data.face ORDER BY face_id;
 
+-----------------------------------------------------
+-- Check robustness in presence of corrupted topology
+-----------------------------------------------------
+
+-- See https://trac.osgeo.org/postgis/ticket/4709
+BEGIN; -- need a transaction to corrupt the topology
+-- 1. Corrupt topology by setting edge 5 next_left_edge = 999999 (instead of -4)
+UPDATE city_data.edge_data
+  SET
+    next_left_edge = 999999,
+    abs_next_left_edge = 999999
+  WHERE edge_id = 5; -- corrupt topology
+-- 2. Try to add an edge closing a ring involving edge 5
+SELECT ST_AddEdgeModFace('city_data', 5, 7, 'LINESTRING(36 38,41 40)');
+ROLLBACK; -- restores the topology
+
 ---------------------------------------------------------------------
 -- Cleanups
 ---------------------------------------------------------------------
diff --git a/topology/test/regress/st_addedgemodface_expected b/topology/test/regress/st_addedgemodface_expected
index cfc96e0..55ccf03 100644
--- a/topology/test/regress/st_addedgemodface_expected
+++ b/topology/test/regress/st_addedgemodface_expected
@@ -206,4 +206,5 @@ F32|POLYGON((36 33,36 38,57 38,57 33,36 33))
 F33|POLYGON((38 40,38 43,41 43,41 40,38 40))
 F34|POLYGON((35 25,35 45,63 45,63 25,35 25))
 F35|POLYGON((9 14,9 22,21 22,21 14,9 14))
+ERROR:  Backend error (no ring edges for edge 58): Corrupted topology: ring of edge 58 is topologically non-closed
 Topology 'city_data' dropped

commit 037eba580cc6de9b4a2bc5c4777bb081bad401f1
Author: Sandro Santilli <strk at kbt.io>
Date:   Fri Jun 26 12:01:47 2020 +0200

    Fix release of unexpected number of edges from a returned edge ring
    
    References #4709 in 3.0 branch

diff --git a/liblwgeom/lwgeom_topo.c b/liblwgeom/lwgeom_topo.c
index 0926888..f140d8f 100644
--- a/liblwgeom/lwgeom_topo.c
+++ b/liblwgeom/lwgeom_topo.c
@@ -1771,7 +1771,7 @@ _lwt_MakeRingShell(LWT_TOPOLOGY *topo, LWT_ELEMID *signed_edge_ids, uint64_t num
   else if ( i != numedges )
   {
     lwfree( signed_edge_ids );
-    _lwt_release_edges(ring_edges, numedges);
+    _lwt_release_edges(ring_edges, i);
     lwerror("Unexpected error: %d edges found when expecting %d", i, numedges);
     return NULL;
   }

-----------------------------------------------------------------------

Summary of changes:
 NEWS                                             |  2 ++
 liblwgeom/lwgeom_topo.c                          | 10 ++++++-
 topology/postgis_topology.c                      | 34 ++++++++++++++++++++++++
 topology/test/regress/st_addedgemodface.sql      | 16 +++++++++++
 topology/test/regress/st_addedgemodface_expected |  1 +
 5 files changed, 62 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list