[postgis-tickets] [SCM] PostGIS branch stable-2.5 updated. 2.5.4-20-g65e73de

git at osgeo.org git at osgeo.org
Mon Jun 29 02:35:44 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-2.5 has been updated
       via  65e73de493df9d0bcc1ddb8762756ab2e8b069ed (commit)
       via  456ee529a787dfa44b53f0e2fb6a7e18d693cc20 (commit)
       via  8258c1668350282a678e914b447f85568590d2f9 (commit)
      from  778d66b336f613e1072ff53b2e206a51d344d706 (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 65e73de493df9d0bcc1ddb8762756ab2e8b069ed
Author: Sandro Santilli <strk at kbt.io>
Date:   Mon Jun 29 11:24:56 2020 +0200

    Update NEWS file

diff --git a/NEWS b/NEWS
index 291bb5f..5e5c212 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ PostGIS 2.5.5
 
  * Bug fixes *
 
+  - #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 456ee529a787dfa44b53f0e2fb6a7e18d693cc20
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 2.5 branch

diff --git a/liblwgeom/lwgeom_topo.c b/liblwgeom/lwgeom_topo.c
index 8b0bca8..308f64e 100644
--- a/liblwgeom/lwgeom_topo.c
+++ b/liblwgeom/lwgeom_topo.c
@@ -1899,6 +1899,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 adb0c51..abb70e5 100644
--- a/topology/postgis_topology.c
+++ b/topology/postgis_topology.c
@@ -1248,8 +1248,41 @@ cb_getRingEdges(const LWT_BE_TOPOLOGY* topo,
     }
     val = DatumGetInt32(dat);
     edges[i] = val;
-    POSTGIS_DEBUGF(1, "Component %d in ring of edge %" LWTFMT_ELEMID
-                   " is edge %d", i, edge, 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 cb03d42..92d99e6 100644
--- a/topology/test/regress/st_addedgemodface_expected
+++ b/topology/test/regress/st_addedgemodface_expected
@@ -208,4 +208,7 @@ 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))
+BEGIN
+ERROR:  Backend error (no ring edges for edge 58): Corrupted topology: ring of edge 58 is topologically non-closed
+COMMIT
 Topology 'city_data' dropped

commit 8258c1668350282a678e914b447f85568590d2f9
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 2.5 branch

diff --git a/liblwgeom/lwgeom_topo.c b/liblwgeom/lwgeom_topo.c
index 073bb03..8b0bca8 100644
--- a/liblwgeom/lwgeom_topo.c
+++ b/liblwgeom/lwgeom_topo.c
@@ -1773,7 +1773,7 @@ _lwt_MakeRingShell(LWT_TOPOLOGY *topo, LWT_ELEMID *signed_edge_ids, int num_sign
   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                      | 37 ++++++++++++++++++++++--
 topology/test/regress/st_addedgemodface.sql      | 16 ++++++++++
 topology/test/regress/st_addedgemodface_expected |  3 ++
 5 files changed, 65 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list