]> granicus.if.org Git - postgis/commitdiff
Raise an error when fed KML with mixed coordinate dimension
authorSandro Santilli <strk@keybit.net>
Mon, 1 Jul 2013 09:17:23 +0000 (09:17 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 1 Jul 2013 09:17:23 +0000 (09:17 +0000)
See #2372

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

postgis/lwgeom_in_kml.c
regress/in_kml.sql
regress/in_kml_expected

index d853ae8a9462e61a605a023cede4c50678e62914..3180c2d4d6dac00fb3d29a0b29d66b84ffa32ad3 100644 (file)
@@ -269,6 +269,7 @@ static POINTARRAY* parse_kml_coordinates(xmlNodePtr xnode, bool *hasz)
        xmlChar *kml_coord;
        bool found;
        POINTARRAY *dpa;
+       int seen_kml_dims = 0;
        int kml_dims;
        char *p, *q;
        POINT4D pt;
@@ -328,7 +329,11 @@ static POINTARRAY* parse_kml_coordinates(xmlNodePtr xnode, bool *hasz)
         while (*q && isspace(*q)) ++q;
         if ( isdigit(*q) || *q == '+' || *q == '-' || *q == '.' || ! *q ) {
           if ( kml_dims < 2 ) lwerror("invalid KML representation"); /* (not enough ordinates)"); */
-          if ( kml_dims < 3 ) *hasz = false;
+          else if ( kml_dims < 3 ) *hasz = false;
+          if ( ! seen_kml_dims ) seen_kml_dims = kml_dims;
+          else if ( seen_kml_dims != kml_dims ) {
+            lwerror("invalid KML representation: mixed coordinates dimension");
+          }
           ptarray_append_point(dpa, &pt, LW_FALSE);
           kml_dims = 0;
         }
index c02e7608880f21215b2032226600b05703ee6541..3ac14e0c323db3b1d92836742baa909fab9922ea 100644 (file)
@@ -351,6 +351,10 @@ SELECT 'double_30', ST_AsEWKT(ST_GeomFromKML('<kml:Point><kml:coordinates>1,-1.2
 -- ERROR: Junk 
 SELECT 'double_31', ST_AsEWKT(ST_GeomFromKML('<kml:Point><kml:coordinates>1,$0%@#$^%#</kml:coordinates></kml:Point>'));
 
+-- ERROR: mixed coordinate dimension
+SELECT 'mixed_dims_1', ST_AsEWKT(ST_GeomFromKML('<kml:Point><kml:coordinates>1,2 1,2,3</kml:coordinates></kml:Point>'));
+SELECT 'mixed_dims_2', ST_AsEWKT(ST_GeomFromKML('<kml:Point><kml:coordinates>1,2,3 1,2</kml:coordinates></kml:Point>'));
+
 
 
 
index 063b9ea6d05813ffcc0f06eff1f387c429e7017a..0203db68543051c52ff2538d8cd0951eaf8582f4 100644 (file)
@@ -98,3 +98,5 @@ ERROR:  invalid KML representation
 ERROR:  invalid KML representation
 ERROR:  invalid KML representation
 ERROR:  invalid KML representation
+ERROR:  invalid KML representation: mixed coordinates dimension
+ERROR:  invalid KML representation: mixed coordinates dimension