]> granicus.if.org Git - postgis/commitdiff
Guard against NaN values in coordinates passing into GEOS (#627)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 8 Dec 2011 22:16:08 +0000 (22:16 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 8 Dec 2011 22:16:08 +0000 (22:16 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8328 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_libgeom.c
liblwgeom/lwgeom_geos.c
postgis/lwgeom_geos.c

index 4a9258c64fb51da4f6c3376a44dfd033b4dd0783..27f134713f9625c435fee58ce91215822faed6f4 100644 (file)
@@ -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));
index 4300b1e84c6ad48f788f201908cfb414f9ed9fe9..5942e856f7a00632e3b5b675e1b6aa975632c768 100644 (file)
@@ -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);
index f05e60fc3ababebcabd5f0c16d5f817904b7be03..134b4ed9cd47f54d2a1da85e84d250d7c60d7371 100644 (file)
@@ -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);
                }
        }