[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 3.0.8-4-g92e739924
git at osgeo.org
git at osgeo.org
Thu Feb 16 22:43:03 PST 2023
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 92e7399245050479ce0c464279d6f6aac80d551e (commit)
from 400317a3cb36c77c94bc61e0709b5744fef0bbfe (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 92e7399245050479ce0c464279d6f6aac80d551e
Author: Regina Obe <lr at pcorp.us>
Date: Fri Feb 17 01:35:08 2023 -0500
Prefilter to check for non-finite coordinates before feeding
ST_SimplifyPreserveTopology, ST_Buffer, ST_SetPoint
to avoid crash/hang.
References #5320
References #5315
References #5319
for PostGIS 3.0.9
diff --git a/NEWS b/NEWS
index d5ead5c73..e22648026 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ xxxx/xx/xx
* Bug Fixes *
- #5338, Dump/Restore of raster table fails on
enforce_coverage_tile_rast constraint (Regina Obe)
+ - #5315, #5319, #5320 crashes on infinite coordinates
+ (Regina Obe, Paul Ramsey)
PostGIS 3.0.8
2022/11/11
diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in
index 3e01ee197..c8fb31e7d 100644
--- a/liblwgeom/liblwgeom.h.in
+++ b/liblwgeom/liblwgeom.h.in
@@ -884,6 +884,12 @@ extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom);
*/
extern int lwgeom_is_collection(const LWGEOM *lwgeom);
+/**
+* Check if a LWGEOM has any non-finite (NaN or Inf) coordinates.
+*/
+extern int lwgeom_isfinite(const LWGEOM *lwgeom);
+
+
/******************************************************************/
/* Functions that work on type numbers */
diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c
index a07ca53a1..6e13e35a0 100644
--- a/liblwgeom/lwgeom.c
+++ b/liblwgeom/lwgeom.c
@@ -2524,3 +2524,29 @@ void lwgeom_trim_bits_in_place(LWGEOM* geom, int32_t prec_x, int32_t prec_y, int
lwpointiterator_destroy(it);
}
+
+int
+lwgeom_isfinite(const LWGEOM *lwgeom)
+{
+ LWPOINTITERATOR* it = lwpointiterator_create(lwgeom);
+ int hasz = lwgeom_has_z(lwgeom);
+ int hasm = lwgeom_has_m(lwgeom);
+
+ while (lwpointiterator_has_next(it))
+ {
+ POINT4D p;
+ lwpointiterator_next(it, &p);
+ int finite = isfinite(p.x) &&
+ isfinite(p.y) &&
+ (hasz ? isfinite(p.z) : 1) &&
+ (hasm ? isfinite(p.m) : 1);
+
+ if (!finite)
+ {
+ lwpointiterator_destroy(it);
+ return LW_FALSE;
+ }
+ }
+ lwpointiterator_destroy(it);
+ return LW_TRUE;
+}
diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c
index 83ec8aa0b..5de03d1c1 100644
--- a/postgis/lwgeom_functions_basic.c
+++ b/postgis/lwgeom_functions_basic.c
@@ -2320,15 +2320,24 @@ Datum LWGEOM_setpoint_linestring(PG_FUNCTION_ARGS)
lwg = lwgeom_from_gserialized(pglwg1);
line = lwgeom_as_lwline(lwg);
+
if (!line)
{
elog(ERROR, "First argument must be a LINESTRING");
PG_RETURN_NULL();
}
+
if ( line->points->npoints < 1 ) {
elog(ERROR, "Line has no points");
PG_RETURN_NULL();
}
+
+ if (!lwgeom_isfinite(lwg))
+ {
+ elog(ERROR, "Geometry contains invalid coordinate");
+ PG_RETURN_NULL();
+ }
+
if (which < 0)
{
/* Use backward indexing for negative values */
diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c
index 6eebc72b3..f06826189 100644
--- a/postgis/lwgeom_geos.c
+++ b/postgis/lwgeom_geos.c
@@ -831,23 +831,32 @@ Datum convexhull(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(topologypreservesimplify);
Datum topologypreservesimplify(PG_FUNCTION_ARGS)
{
- GSERIALIZED *geom1;
+ GSERIALIZED *gs1;
+ LWGEOM *lwg1;
double tolerance;
GEOSGeometry *g1, *g3;
GSERIALIZED *result;
uint32_t type;
- geom1 = PG_GETARG_GSERIALIZED_P(0);
+ gs1 = PG_GETARG_GSERIALIZED_P(0);
tolerance = PG_GETARG_FLOAT8(1);
+ lwg1 = lwgeom_from_gserialized(gs1);
/* Empty.Simplify() == Empty */
- type = gserialized_get_type(geom1);
- if ( gserialized_is_empty(geom1) || type == TINTYPE || type == TRIANGLETYPE )
- PG_RETURN_POINTER(geom1);
+ type = lwgeom_get_type(lwg1);
+ if (lwgeom_is_empty(lwg1) || type == TINTYPE || type == TRIANGLETYPE)
+ PG_RETURN_POINTER(gs1);
+
+ if (!lwgeom_isfinite(lwg1))
+ {
+ lwpgerror("Geometry contains invalid coordinates");
+ PG_RETURN_NULL();
+ }
initGEOS(lwpgnotice, lwgeom_geos_error);
- g1 = POSTGIS2GEOS(geom1);
+ g1 = LWGEOM2GEOS(lwg1, LW_TRUE);
+ lwgeom_free(lwg1);
if (!g1)
HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
@@ -858,9 +867,9 @@ Datum topologypreservesimplify(PG_FUNCTION_ARGS)
POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3));
- GEOSSetSRID(g3, gserialized_get_srid(geom1));
+ GEOSSetSRID(g3, gserialized_get_srid(gs1));
- result = GEOS2POSTGIS(g3, gserialized_has_z(geom1));
+ result = GEOS2POSTGIS(g3, gserialized_has_z(gs1));
GEOSGeom_destroy(g3);
if (!result)
@@ -869,7 +878,7 @@ Datum topologypreservesimplify(PG_FUNCTION_ARGS)
PG_RETURN_NULL(); /* never get here */
}
- PG_FREE_IF_COPY(geom1, 0);
+ PG_FREE_IF_COPY(gs1, 0);
PG_RETURN_POINTER(result);
}
@@ -915,7 +924,7 @@ Datum buffer(PG_FUNCTION_ARGS)
SET_VARSIZE(params_text, 0);
}
- /* Empty.Buffer() == Empty[polygon] */
+ /* Empty.Buffer() == Empty[polygon] */
if ( gserialized_is_empty(geom1) )
{
lwg = lwpoly_as_lwgeom(lwpoly_construct_empty(
@@ -924,6 +933,15 @@ Datum buffer(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(geometry_serialize(lwg));
}
+ lwg = lwgeom_from_gserialized(geom1);
+
+ if (!lwgeom_isfinite(lwg))
+ {
+ lwpgerror("Geometry contains invalid coordinates");
+ PG_RETURN_NULL();
+ }
+ lwgeom_free(lwg);
+
initGEOS(lwpgnotice, lwgeom_geos_error);
g1 = POSTGIS2GEOS(geom1);
diff --git a/regress/core/setpoint.sql b/regress/core/setpoint.sql
index 51519ac54..553e50309 100644
--- a/regress/core/setpoint.sql
+++ b/regress/core/setpoint.sql
@@ -26,3 +26,6 @@ SELECT ST_asewkt(ST_SetPoint('LINESTRING(0 0 0 0, 1 1 1 1, 2 2 2 2, 4 4 4 4)', 2
SELECT ST_asewkt(ST_SetPoint('LINESTRING(0 0 0 0, 1 1 1 1, 2 2 2 2, 4 4 4 4)', 1, 'POINTM(90 91 92)'));
SELECT ST_asewkt(ST_SetPoint('LINESTRING(0 0 0 0, 1 1 1 1, 2 2 2 2, 4 4 4 4)', 0, 'POINT(90 91 92 93)'));
+-- https://trac.osgeo.org/postgis/ticket/5319
+SELECT '#5319', ST_SetPoint('0102000020E610000005000000000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F'::geometry, 1,ST_GeomFromText('POINT(0 0)',4326) ) As result;
+
diff --git a/regress/core/setpoint_expected b/regress/core/setpoint_expected
index 210195c40..cbc622b07 100644
--- a/regress/core/setpoint_expected
+++ b/regress/core/setpoint_expected
@@ -11,3 +11,4 @@ LINESTRING(0 0 0 0,1 1 1 1,2 2 2 2,90 91 0 0)
LINESTRING(0 0 0 0,1 1 1 1,90 91 92 0,4 4 4 4)
LINESTRING(0 0 0 0,90 91 0 92,2 2 2 2,4 4 4 4)
LINESTRING(90 91 92 93,1 1 1 1,2 2 2 2,4 4 4 4)
+ERROR: Geometry contains invalid coordinate
diff --git a/regress/core/tickets.sql b/regress/core/tickets.sql
index 69c36f5e2..08e2ffe55 100644
--- a/regress/core/tickets.sql
+++ b/regress/core/tickets.sql
@@ -1388,3 +1388,8 @@ SELECT '#4770.c', ST_AsText(g), s FROM w;
-- https://trac.osgeo.org/postgis/ticket/5151
SELECT '#5151', ST_SetPoint(ST_GeomFromText('LINESTRING EMPTY',4326), 1, ST_GeomFromText('POINT(40 50)',4326)) As result;
+
+-- https://trac.osgeo.org/postgis/ticket/5315
+SELECT '#5315', ST_Buffer('0106000020E86400000100000001030000000100000005000000000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F'::geometry, 1);
+
+SELECT '#5320', ST_SimplifyPreserveTopology('0106000020E86400000100000001030000000100000005000000000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F000000000000F07F'::geometry, 1);
diff --git a/regress/core/tickets_expected b/regress/core/tickets_expected
index a11023589..2f3094a8a 100644
--- a/regress/core/tickets_expected
+++ b/regress/core/tickets_expected
@@ -455,3 +455,5 @@ ERROR: LWGEOM_addpoint: Invalid offset
#4770.c|POINT(0 0)|300
#4770.c|MULTIPOINT(0 0,1 1)|602
ERROR: Line has no points
+ERROR: Geometry contains invalid coordinates
+ERROR: Geometry contains invalid coordinates
-----------------------------------------------------------------------
Summary of changes:
NEWS | 2 ++
liblwgeom/liblwgeom.h.in | 6 ++++++
liblwgeom/lwgeom.c | 26 ++++++++++++++++++++++++++
postgis/lwgeom_functions_basic.c | 9 +++++++++
postgis/lwgeom_geos.c | 38 ++++++++++++++++++++++++++++----------
regress/core/setpoint.sql | 3 +++
regress/core/setpoint_expected | 1 +
regress/core/tickets.sql | 5 +++++
regress/core/tickets_expected | 2 ++
9 files changed, 82 insertions(+), 10 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list