]> granicus.if.org Git - postgis/commitdiff
ST_ClipByBox2D: do not use gbox_overlaps with BOX2DF objects
authorSandro Santilli <strk@keybit.net>
Fri, 3 Oct 2014 09:34:43 +0000 (09:34 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 3 Oct 2014 09:34:43 +0000 (09:34 +0000)
Fixes use of uninitialized memory (#2954)

git-svn-id: http://svn.osgeo.org/postgis/trunk@13034 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_geos.c
regress/clipbybox2d.sql
regress/clipbybox2d_expected

index ce3a5092f932c3743c58a970cbfdf46c51b53bb2..3a81d98623054998599bf40ff06e18c58a0c4662 100644 (file)
@@ -1665,10 +1665,13 @@ Datum ST_ClipByBox2d(PG_FUNCTION_ARGS)
                PG_RETURN_POINTER(geom1);
        }
 
+       /* WARNING: this is really a BOX2DF, use only xmin and ymin fields */
        bbox2 = (GBOX *)PG_GETARG_POINTER(1);
 
-       /* If bbox1 outside of bbox, return empty */
-       if ( LW_FALSE == gbox_overlaps_2d(bbox1, bbox2) ) {
+       /* If bbox1 outside of bbox2, return empty */
+       if ( bbox1->xmin > bbox2->xmax || bbox1->xmax < bbox2->xmin ||
+                        bbox1->ymin > bbox2->ymax || bbox1->ymax < bbox2->ymin )
+       {
                lwresult = lwgeom_construct_empty(lwgeom1->type, lwgeom1->srid, 0, 0);
                lwgeom_free(lwgeom1);
                PG_FREE_IF_COPY(geom1, 0);
@@ -1677,7 +1680,7 @@ Datum ST_ClipByBox2d(PG_FUNCTION_ARGS)
                PG_RETURN_POINTER(result);
        }
 
-       /* if bbox1 is covered by bbox, return lwgeom1 */
+       /* if bbox1 is covered by bbox2, return lwgeom1 */
        if ( bbox1->xmax <= bbox2->xmax && bbox1->xmin >= bbox2->xmin &&
                         bbox1->ymax <= bbox2->ymax && bbox1->ymin >= bbox2->ymin )
        {
index 1c9a4a6f7b57d63ae7231d9613144395f3f32e58..b82207d7da6b5e6857f3c9366d82e28863af2950 100644 (file)
@@ -21,3 +21,5 @@ CREATE TEMPORARY TABLE t AS SELECT
 'SRID=3857;POLYGON((41 20,41 0,21 0,1 20,1 40,21 40,41 20))'
 ::geometry g;
 SELECT ST_AsEWKT(ST_ClipByBox2d(g, ST_MakeEnvelope(-20,-20,-10,-10))) FROM t;
+-- See http://trac.osgeo.org/postgis/ticket/2954
+SELECT ST_AsEWKT(ST_ClipByBox2D('SRID=4326;POINT(0 0)','BOX3D(-1 -1,1 1)'::box3d::box2d));
index 8243e44fafff5c17eb94ff467cf07a0a10820ea6..e58bf780c5af4d7ebffa5975b78ff882e078b948 100644 (file)
@@ -6,3 +6,4 @@ POLYGON((2 2,8 2,2 8,8 8,2 2))
 POLYGON((2.5 2,5 4,5 5,5 4,7.5 2,2.5 2))
 POLYGON((2 2,2 5,5 5,5 2,2 2))
 SRID=3857;POLYGON EMPTY
+SRID=4326;POINT(0 0)