[postgis-tickets] [SCM] PostGIS branch stable-2.3 updated. cb4666e71622d1755aa88c3b567670786ee87632

git at osgeo.org git at osgeo.org
Mon Mar 30 03:21:40 PDT 2020


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, stable-2.3 has been updated
       via  cb4666e71622d1755aa88c3b567670786ee87632 (commit)
       via  1dc925025e1ec9ffb359940970a1d164abdf054a (commit)
      from  a960d43f055d6532afcfd6559b40c0ec64d7a392 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit cb4666e71622d1755aa88c3b567670786ee87632
Author: Raúl Marín <git at rmr.ninja>
Date:   Fri Mar 27 20:16:18 2020 +0100

    parse_gml_curve: Fix multiple bugs
    
    - ppa was leaked when lss == 1
    - When lss > 1, was trying to copy an extra point at the end.
    
    Closes #4652

diff --git a/NEWS b/NEWS
index bfa2948..b83c1bc 100644
--- a/NEWS
+++ b/NEWS
@@ -4,7 +4,7 @@ XXXX/XX/XX
   * Bug Fixes and Enhancements *
 
   - #4475, Avoid reading into empty ptarray (Paul Ramsey)
-  - #4518, Fix geometry_columns and raster views 
+  - #4518, Fix geometry_columns and raster views
           to not use pg_constraints.consrc which was removed in PG 12 (Regina Obe)
   - #4492, Fix ST_Simplify ignoring the value of the 3rd parameter (Raúl Marín)
   - #4494, Fix ST_Simplify output having an outdated bbox (Raúl Marín)
@@ -19,6 +19,7 @@ XXXX/XX/XX
   - #4549, Fix schema qualification of internal types (Raúl Marín)
   - #4546, Fix PLPGSQL functions missing the schema qualification (Raúl Marín)
   - #4621, Prevent stack overflow when parsing WKB (Raúl Marín)
+  - #4652, Fix several memory related bugs in ST_GeomFromGML (Raúl Marín)
 
 PostGIS 2.3.10
 2019/08/11
diff --git a/postgis/lwgeom_in_gml.c b/postgis/lwgeom_in_gml.c
index 9d574ed..f221a67 100644
--- a/postgis/lwgeom_in_gml.c
+++ b/postgis/lwgeom_in_gml.c
@@ -697,7 +697,7 @@ static POINTARRAY* parse_gml_pos(xmlNodePtr xnode, bool *hasz)
 	POINTARRAY *dpa;
 	char *pos, *p;
 	bool digit;
-	POINT4D pt;
+	POINT4D pt = {0, 0, 0, 0};
 
 	/* HasZ, !HasM, 1 Point */
 	dpa = ptarray_construct_empty(1, 0, 1);
@@ -763,7 +763,7 @@ static POINTARRAY* parse_gml_poslist(xmlNodePtr xnode, bool *hasz)
 	char *poslist, *p;
 	int dim, gml_dim;
 	POINTARRAY *dpa;
-	POINT4D pt;
+	POINT4D pt = {0, 0, 0, 0};
 	bool digit;
 
 	/* Retrieve gml:srsDimension attribute if any */
@@ -805,6 +805,7 @@ static POINTARRAY* parse_gml_poslist(xmlNodePtr xnode, bool *hasz)
 			if (gml_dim == dim)
 			{
 				ptarray_append_point(dpa, &pt, LW_FALSE);
+				pt.x = pt.y = pt.z = pt.m = 0.0;
 				gml_dim = 0;
 			}
 			else if (*(poslist+1) == '\0')
@@ -994,7 +995,7 @@ static LWGEOM* parse_gml_line(xmlNodePtr xnode, bool *hasz, int *root_srid)
 static LWGEOM* parse_gml_curve(xmlNodePtr xnode, bool *hasz, int *root_srid)
 {
 	xmlNodePtr xa;
-	int lss, last, i;
+	size_t lss;
 	bool found=false;
 	gmlSrs srs;
 	LWGEOM *geom=NULL;
@@ -1050,37 +1051,45 @@ static LWGEOM* parse_gml_curve(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	/* Most common case, a single segment */
 	if (lss == 1) pa = ppa[0];
 
-	/*
-	 * "The curve segments are connected to one another, with the end point
-	 *  of each segment except the last being the start point of the next
-	 *  segment"  from  ISO 19107:2003 -> 6.3.16.1 (p43)
-	 *
-	 * So we must aggregate all the segments into a single one and avoid
-	 * to copy the redundants points
-	 */
 	if (lss > 1)
 	{
-		pa = ptarray_construct(1, 0, npoints - (lss - 1));
-		for (last = npoints = i = 0; i < lss ; i++)
+		/*
+		 * "The curve segments are connected to one another, with the end point
+		 *  of each segment except the last being the start point of the next
+		 *  segment"  from  ISO 19107:2003 -> 6.3.16.1 (p43)
+		 *
+		 * So we must aggregate all the segments into a single one and avoid
+		 * to copy the redundant points
+		 */
+		size_t cp_point_size = sizeof(POINT3D); /* All internals are done with 3D */
+		size_t final_point_size = *hasz ? sizeof(POINT3D) : sizeof(POINT2D);
+		pa = ptarray_construct(1, 0, npoints - lss + 1);
+
+		/* Copy the first linestring fully */
+		memcpy(getPoint_internal(pa, 0), getPoint_internal(ppa[0], 0), cp_point_size * (ppa[0]->npoints));
+		npoints = ppa[0]->npoints;
+		lwfree(ppa[0]);
+
+		/* For the rest of linestrings, ensure the first point matches the
+		 * last point of the previous one, and copy all points except the
+		 * first one (since it'd be repeated)
+		 */
+		for (size_t i = 1; i < lss; i++)
 		{
-			if (i + 1 == lss) last = 1;
-			/* Check if segments are not disjoints */
-			if (i > 0 && memcmp( getPoint_internal(pa, npoints),
-			                     getPoint_internal(ppa[i], 0),
-			                     *hasz ? sizeof(POINT3D) : sizeof(POINT2D)))
+			if (memcmp(getPoint_internal(pa, npoints - 1), getPoint_internal(ppa[i], 0), final_point_size))
 				gml_lwpgerror("invalid GML representation", 41);
 
-			/* Aggregate stuff */
-			memcpy(	getPoint_internal(pa, npoints),
-			        getPoint_internal(ppa[i], 0),
-			        ptarray_point_size(ppa[i]) * (ppa[i]->npoints + last));
+			memcpy(getPoint_internal(pa, npoints),
+			       getPoint_internal(ppa[i], 1),
+			       cp_point_size * (ppa[i]->npoints - 1));
 
 			npoints += ppa[i]->npoints - 1;
 			lwfree(ppa[i]);
 		}
-		lwfree(ppa);
 	}
 
+	lwfree(ppa);
+
 	parse_gml_srs(xnode, &srs);
 	if (srs.reverse_axis) pa = ptarray_flip_coordinates(pa);
 	if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
diff --git a/regress/in_gml.sql b/regress/in_gml.sql
index d84f82a..251ff90 100644
--- a/regress/in_gml.sql
+++ b/regress/in_gml.sql
@@ -17,7 +17,8 @@ INSERT INTO "spatial_ref_sys" ("srid","auth_name","auth_srid","srtext","proj4tex
 --- EPSG 27582 : NTF (Paris) / France II (deprecated)
 INSERT INTO "spatial_ref_sys" ("srid","auth_name","auth_srid","srtext","proj4text") VALUES (27582,'EPSG',27582,'PROJCS["NTF (Paris) / France II (deprecated)",GEOGCS["NTF (Paris)",DATUM["Nouvelle_Triangulation_Francaise_Paris",SPHEROID["Clarke 1880 (IGN)",6378249.2,293.4660212936265,AUTHORITY["EPSG","7011"]],TOWGS84[-168,-60,320,0,0,0,0],AUTHORITY["EPSG","6807"]],PRIMEM["Paris",2.33722917,AUTHORITY["EPSG","8903"]],UNIT["grad",0.01570796326794897,AUTHORITY["EPSG","9105"]],AUTHORITY["EPSG","4807"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_1SP"],PARAMETER["latitude_of_origin",52],PARAMETER["central_meridian",0],PARAMETER["scale_factor",0.99987742],PARAMETER["false_easting",600000],PARAMETER["false_northing",2200000],AUTHORITY["EPSG","27582"],AXIS["X",EAST],AXIS["Y",NORTH]]','+proj=lcc +lat_1=46.8 +lat_0=46.8 +lon_0=0 +k_0=0.99987742 +x_0=600000 +y_0=2200000 +a=6378249.2 +b=6356515 +towgs84=-168,-60,320,0,0,0,0 +pm=paris +units=m +no_defs ');
 
-
+--- EPSG 28992
+INSERT INTO "spatial_ref_sys" ("srid","auth_name","auth_srid","srtext","proj4text") VALUES (28992,'EPSG',28992,'PROJCS["Amersfoort / RD New",GEOGCS["Amersfoort",DATUM["Amersfoort",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],TOWGS84[565.2369,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812],AUTHORITY["EPSG","6289"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4289"]],PROJECTION["Oblique_Stereographic"],PARAMETER["latitude_of_origin",52.15616055555555],PARAMETER["central_meridian",5.38763888888889],PARAMETER["scale_factor",0.9999079],PARAMETER["false_easting",155000],PARAMETER["false_northing",463000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","28992"]]','+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.2369,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0
 812 +units=m +no_defs');
 
 
 -- Empty Geometry
@@ -1318,7 +1319,8 @@ SELECT 'double_30', ST_AsEWKT(ST_GeomFromGML('<gml:Point><gml:pos>1 -1.23E 2</gm
 SELECT 'double_31', ST_AsEWKT(ST_GeomFromGML('<gml:Point><gml:pos>1 $0%@#$^%#</gml:pos></gml:Point>'));
 
 
-
+-- #4652
+SELECT '#4652', ST_AsEWKT(ST_GeomFromGML('<gml:Curve id="id-69b216c9-2c07-434d-8664-e321b3697725-0" srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:28992"> <gml:segments> <gml:LineStringSegment> <gml:posList>119675.91899999976 526436.1209999993 119676.54699999839 526439.4930000007 119676.44299999997 526439.5130000003 119676.03299999982 526439.6220000014 119675.38500000164 526439.868999999</gml:posList> </gml:LineStringSegment> <gml:LineStringSegment> <gml:posList>119675.38500000164 526439.868999999 119675.15500452081 526439.9735735222 119674.92922525379 526440.0869634049 119674.70800000057 526440.2089999989</gml:posList> </gml:LineStringSegment> <gml:LineStringSegment> <gml:posList>119674.70800000057 526440.2089999989 119674.01347910661 526440.6575801083 119673.38748824484 526441.1976901226</gml:posList> </gml:LineStringSegment> </gml:segments> </gml:Curve>',28992));
 
 --
 -- Delete inserted spatial data
@@ -1326,3 +1328,4 @@ SELECT 'double_31', ST_AsEWKT(ST_GeomFromGML('<gml:Point><gml:pos>1 $0%@#$^%#</g
 DELETE FROM spatial_ref_sys WHERE srid = 4326;
 DELETE FROM spatial_ref_sys WHERE srid = 27562;
 DELETE FROM spatial_ref_sys WHERE srid = 27582;
+DELETE FROM spatial_ref_sys WHERE srid = 28992;
diff --git a/regress/in_gml_expected b/regress/in_gml_expected
index 6fa4e2d..5e0ff9a 100644
--- a/regress/in_gml_expected
+++ b/regress/in_gml_expected
@@ -432,3 +432,4 @@ ERROR:  invalid GML representation
 ERROR:  invalid GML representation
 ERROR:  invalid GML representation
 ERROR:  invalid GML representation
+#4652|SRID=28992;LINESTRING(119675.919 526436.120999999,119676.546999998 526439.493000001,119676.443 526439.513,119676.033 526439.622000001,119675.385000002 526439.868999999,119675.155004521 526439.973573522,119674.929225254 526440.086963405,119674.708000001 526440.208999999,119674.013479107 526440.657580108,119673.387488245 526441.197690123)

commit 1dc925025e1ec9ffb359940970a1d164abdf054a
Author: Raúl Marín <git at rmr.ninja>
Date:   Fri Mar 27 18:05:31 2020 +0100

    lwgeom_from_gml: Only calculate the bbox after the geometry has been uniformized
    
    Since the gserialization will done if (and only if necessary,
    so it's a performance win), we don't do it ourselves in the
    function

diff --git a/postgis/lwgeom_in_gml.c b/postgis/lwgeom_in_gml.c
index bbce406..9d574ed 100644
--- a/postgis/lwgeom_in_gml.c
+++ b/postgis/lwgeom_in_gml.c
@@ -1820,9 +1820,6 @@ static LWGEOM* lwgeom_from_gml(const char* xml)
 	if ( root_srid != SRID_UNKNOWN )
 		lwgeom->srid = root_srid;
 
-	/* Should we really do this here ? */
-	lwgeom_add_bbox(lwgeom);
-
 	/* GML geometries could be either 2 or 3D and can be nested mixed.
 	 * Missing Z dimension is even tolerated inside some GML coords
 	 *

-----------------------------------------------------------------------

Summary of changes:
 NEWS                    |  3 ++-
 postgis/lwgeom_in_gml.c | 58 +++++++++++++++++++++++++++----------------------
 regress/in_gml.sql      |  7 ++++--
 regress/in_gml_expected |  1 +
 4 files changed, 40 insertions(+), 29 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list