From: Nicklas Avén Date: Sun, 28 Jun 2015 16:56:24 +0000 (+0000) Subject: Prevent mixed dimensionality in twkb #3186 X-Git-Tag: 2.2.0rc1~307 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59ef29177b5f79c7447548f4131ea5ef55db7d5d;p=postgis Prevent mixed dimensionality in twkb #3186 git-svn-id: http://svn.osgeo.org/postgis/trunk@13731 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/lwgeom_inout.c b/postgis/lwgeom_inout.c index 683d2cc48..5e2a7c60e 100644 --- a/postgis/lwgeom_inout.c +++ b/postgis/lwgeom_inout.c @@ -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;