From: Paul Ramsey Date: Thu, 8 Dec 2011 22:16:08 +0000 (+0000) Subject: Guard against NaN values in coordinates passing into GEOS (#627) X-Git-Tag: 2.0.0alpha1~543 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c80ebf1baac69a74a07675ac189252014a5883cc;p=postgis Guard against NaN values in coordinates passing into GEOS (#627) git-svn-id: http://svn.osgeo.org/postgis/trunk@8328 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_libgeom.c b/liblwgeom/cunit/cu_libgeom.c index 4a9258c64..27f134713 100644 --- a/liblwgeom/cunit/cu_libgeom.c +++ b/liblwgeom/cunit/cu_libgeom.c @@ -188,6 +188,7 @@ static void test_lwgeom_calculate_gbox(void) lwgeom_free(g); /* LINESTRING(0 0, 0 Inf) = 00 00000002 00000002 0000000000000000 7FF0000000000000 0000000000000000 0000000000000000 */ + /* Inf should show up in bbox */ g = lwgeom_from_hexwkb("00000000020000000200000000000000007FF000000000000000000000000000000000000000000000", LW_PARSER_CHECK_NONE); lwgeom_calculate_gbox_cartesian(g, &b); CU_ASSERT_DOUBLE_EQUAL(b.xmin, 0.0, 0.0000001); @@ -195,6 +196,7 @@ static void test_lwgeom_calculate_gbox(void) lwgeom_free(g); /* Geometry with NaN 0101000020E8640000000000000000F8FF000000000000F8FF */ + /* NaN should show up in bbox */ g = lwgeom_from_hexwkb("0101000020E8640000000000000000F8FF000000000000F8FF", LW_PARSER_CHECK_NONE); lwgeom_calculate_gbox_cartesian(g, &b); CU_ASSERT(isnan(b.ymax)); diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c index 4300b1e84..5942e856f 100644 --- a/liblwgeom/lwgeom_geos.c +++ b/liblwgeom/lwgeom_geos.c @@ -216,11 +216,13 @@ ptarray_to_GEOSCoordSeq(const POINTARRAY *pa) LWDEBUGF(4, "Point: %g,%g,%g", p.x, p.y, p.z); - /* Make sure we don't pass any infinite values down into GEOS */ - /* GEOS 3.3+ is supposed to handle this stuff OK */ #if POSTGIS_GEOS_VERSION < 33 - if ( isinf(p.x) || isinf(p.y) || (dims == 3 && isinf(p.z)) ) - lwerror("Infinite coordinate value found in geometry."); + /* Make sure we don't pass any infinite values down into GEOS */ + /* GEOS 3.3+ is supposed to handle this stuff OK */ + if ( isinf(p.x) || isinf(p.y) || (dims == 3 && isinf(p.z)) ) + lwerror("Infinite coordinate value found in geometry."); + if ( isnan(p.x) || isnan(p.y) || (dims == 3 && isnan(p.z)) ) + lwerror("NaN coordinate value found in geometry."); #endif GEOSCoordSeq_setX(sq, i, p.x); diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c index f05e60fc3..134b4ed9c 100644 --- a/postgis/lwgeom_geos.c +++ b/postgis/lwgeom_geos.c @@ -1512,7 +1512,7 @@ Datum isvalid(PG_FUNCTION_ARGS) bool result; GEOSGeom g1; #if POSTGIS_GEOS_VERSION < 33 - GBOX box1; + GBOX box1; #endif geom1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); @@ -1522,14 +1522,14 @@ Datum isvalid(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); #if POSTGIS_GEOS_VERSION < 33 - /* Short circuit and return FALSE if we have infinite coordinates */ - /* GEOS 3.3+ is supposed to handle this stuff OK */ + /* Short circuit and return FALSE if we have infinite coordinates */ + /* GEOS 3.3+ is supposed to handle this stuff OK */ if ( gserialized_get_gbox_p(geom1, &box1) ) { if ( isinf(box1.xmax) || isinf(box1.ymax) || isinf(box1.xmin) || isinf(box1.ymin) || isnan(box1.xmax) || isnan(box1.ymax) || isnan(box1.xmin) || isnan(box1.ymin) ) { - lwnotice("Geometry contains an Inf or NaN coordinate"); + lwnotice("Geometry contains an Inf or NaN coordinate"); PG_RETURN_BOOL(FALSE); } }