]> granicus.if.org Git - postgis/commitdiff
Prevent mixed dimensionality in twkb #3186
authorNicklas Avén <nicklas.aven@jordogskog.no>
Sun, 28 Jun 2015 16:56:24 +0000 (16:56 +0000)
committerNicklas Avén <nicklas.aven@jordogskog.no>
Sun, 28 Jun 2015 16:56:24 +0000 (16:56 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13731 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_inout.c

index 683d2cc48caf3f3c13044efb820bc67eab4c5147..5e2a7c60e891b03d83d5eeff1e25764459b355ac 100644 (file)
@@ -508,6 +508,8 @@ Datum TWKBFromLWGEOMArray(PG_FUNCTION_ARGS)
 
        int is_homogeneous = true;
        int subtype = 0;
+       int has_z = 0;
+       int has_m  = 0;
        LWCOLLECTION *col = NULL;
        int64_t *idlist = NULL;
        uint8_t variant = 0;
@@ -558,13 +560,26 @@ Datum TWKBFromLWGEOMArray(PG_FUNCTION_ARGS)
 
                geom = lwgeom_from_gserialized((GSERIALIZED*)DatumGetPointer(val_geom));
                uid = DatumGetInt64(val_id);
-
+               
                /* Construct collection/idlist first time through */
                if ( ! col )
-                       col = lwcollection_construct_empty(COLLECTIONTYPE, lwgeom_get_srid(geom), lwgeom_has_z(geom), lwgeom_has_m(geom));
+               {
+                       has_z = lwgeom_has_z(geom);
+                       has_m = lwgeom_has_m(geom);
+                       col = lwcollection_construct_empty(COLLECTIONTYPE, lwgeom_get_srid(geom), has_z, has_m);
+               }
                if ( ! idlist ) 
                        idlist = palloc0(num_geoms * sizeof(int64_t));
 
+               
+               /*Check if there is differences in dimmenstionality*/
+               if( lwgeom_has_z(geom)!=has_z || lwgeom_has_m(geom)!=has_m)
+               {
+                       elog(ERROR, "Geometries have differenct dimensionality");
+                       PG_FREE_IF_COPY(arr_geoms, 0);
+                       PG_FREE_IF_COPY(arr_ids, 1);
+                       PG_RETURN_NULL();                       
+               }
                /* Store the values */
                lwcollection_add_lwgeom(col, geom);
                idlist[i++] = uid;