[SCM] PostGIS branch stable-3.5 updated. 3.5.3-8-g05dc210b7

git at osgeo.org git at osgeo.org
Thu Jun 5 14:10:16 PDT 2025


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-3.5 has been updated
       via  05dc210b7f166cec21688756bec203a5134b3853 (commit)
      from  c429b883f8dd380f858dcd0a521c4f89181b9f0e (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 05dc210b7f166cec21688756bec203a5134b3853
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Thu Jun 5 14:09:59 2025 -0700

    Remove crash when using xlink without a gml prefix, references #5912

diff --git a/NEWS b/NEWS
index c293e16a7..151891cfa 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ PostgreSQL 12-18 required. GEOS 3.8+ required. Proj 6.1+ required.
 - #5907, [topology] Fix crash in TopoGeo_AddPolygon with EMPTY input (Sandro Santilli)
 - #5922, [topology] Fix crash in TopoGeo_AddLinestring with EMPTY input (Sandro Santilli)
 - #5921, Crash freeing uninitialized pointer (Arsenii Mukhin)
+- #5912, Crash on GML with xlink and no prefix (Paul Ramsey)
 
 
 PostGIS 3.5.3
diff --git a/postgis/lwgeom_in_gml.c b/postgis/lwgeom_in_gml.c
index 9ccab030b..ae0b96411 100644
--- a/postgis/lwgeom_in_gml.c
+++ b/postgis/lwgeom_in_gml.c
@@ -258,16 +258,29 @@ static xmlNodePtr get_xlink_node(xmlNodePtr xnode)
 	xmlChar *href, *p, *node_id;
 
 	href = xmlGetNsProp(xnode, (xmlChar *)"href", (xmlChar *) XLINK_NS);
-	id = lwalloc((xmlStrlen(xnode->ns->prefix) * 2 + xmlStrlen(xnode->name)
-	              + xmlStrlen(href) + sizeof("//:[@:id='']") + 1));
 	p = href;
 	p++; /* ignore '#' first char */
 
-	/* XPath pattern look like: //gml:point[@gml:id='p1'] */
-	sprintf(id, "//%s:%s[@%s:id='%s']", 	(char *) xnode->ns->prefix,
-	        (char *) xnode->name,
-	        (char *) xnode->ns->prefix,
-	        (char *) p);
+	if (xnode->ns)
+	{
+		id = lwalloc((xmlStrlen(xnode->ns->prefix) * 2 + xmlStrlen(xnode->name) +
+		              xmlStrlen(href) + sizeof("//:[@:id='']") + 1));
+		/* XPath pattern look like: //gml:point[@gml:id='p1'] */
+		sprintf(id, "//%s:%s[@%s:id='%s']",
+		        (char *) xnode->ns->prefix,
+		        (char *) xnode->name,
+		        (char *) xnode->ns->prefix,
+		        (char *) p);
+	}
+	else
+	{
+		id = lwalloc((xmlStrlen(xnode->name) +
+		              xmlStrlen(href) + sizeof("//:[@:id='']") + 1));
+		/* XPath pattern look like: //gml:point[@gml:id='p1'] */
+		sprintf(id, "//%s[@id='%s']",
+		        (char *) xnode->name,
+		        (char *) p);
+	}
 
 	ctx = xmlXPathNewContext(xnode->doc);
 	if (ctx == NULL)
@@ -1004,6 +1017,8 @@ static LWGEOM* parse_gml_point(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	POINTARRAY *pa;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	if (xnode->children == NULL)
 		return lwpoint_as_lwgeom(lwpoint_construct_empty(*root_srid, 0, 0));
@@ -1039,6 +1054,8 @@ static LWGEOM* parse_gml_line(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	POINTARRAY *pa;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	if (xnode->children == NULL)
 		return lwline_as_lwgeom(lwline_construct_empty(*root_srid, 0, 0));
@@ -1080,6 +1097,8 @@ static LWGEOM* parse_gml_curve(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	xmlChar *interpolation=NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	/* Looking for gml:segments */
 	for (xa = xnode->children ; xa != NULL ; xa = xa->next)
@@ -1186,6 +1205,8 @@ static LWGEOM* parse_gml_linearring(xmlNodePtr xnode, bool *hasz, int *root_srid
 	POINTARRAY **ppa = NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 	parse_gml_srs(xnode, &srs);
 
 	ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
@@ -1220,6 +1241,8 @@ static LWGEOM* parse_gml_polygon(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	POINTARRAY **ppa = NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	if (xnode->children == NULL)
 		return lwpoly_as_lwgeom(lwpoly_construct_empty(*root_srid, 0, 0));
@@ -1314,6 +1337,8 @@ static LWGEOM* parse_gml_triangle(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	xmlChar *interpolation=NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	if (xnode->children == NULL)
 		return lwtriangle_as_lwgeom(lwtriangle_construct_empty(*root_srid, 0, 0));
@@ -1480,6 +1505,8 @@ static LWGEOM* parse_gml_surface(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	bool found=false;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	/* Looking for gml:patches */
 	for (xa = xnode->children ; xa != NULL ; xa = xa->next)
@@ -1532,6 +1559,8 @@ static LWGEOM* parse_gml_tin(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	bool found=false;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	parse_gml_srs(xnode, &srs);
 	if (*root_srid == SRID_UNKNOWN && srs.srid != SRID_UNKNOWN)
@@ -1582,6 +1611,8 @@ static LWGEOM* parse_gml_mpoint(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	LWGEOM *geom = NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	parse_gml_srs(xnode, &srs);
 	if (*root_srid == SRID_UNKNOWN && srs.srid != SRID_UNKNOWN)
@@ -1628,6 +1659,8 @@ static LWGEOM* parse_gml_mline(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	LWGEOM *geom = NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	parse_gml_srs(xnode, &srs);
 	if (*root_srid == SRID_UNKNOWN && srs.srid != SRID_UNKNOWN)
@@ -1663,6 +1696,8 @@ static LWGEOM* parse_gml_mcurve(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	LWGEOM *geom = NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	parse_gml_srs(xnode, &srs);
 	if (*root_srid == SRID_UNKNOWN && srs.srid != SRID_UNKNOWN)
@@ -1710,6 +1745,8 @@ static LWGEOM* parse_gml_mpoly(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	LWGEOM *geom = NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	parse_gml_srs(xnode, &srs);
 	if (*root_srid == SRID_UNKNOWN && srs.srid != SRID_UNKNOWN)
@@ -1745,6 +1782,8 @@ static LWGEOM* parse_gml_msurface(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	LWGEOM *geom = NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	parse_gml_srs(xnode, &srs);
 	if (*root_srid == SRID_UNKNOWN && srs.srid != SRID_UNKNOWN)
@@ -1793,6 +1832,8 @@ static LWGEOM* parse_gml_psurface(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	LWGEOM *geom = NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	parse_gml_srs(xnode, &srs);
 	if (*root_srid == SRID_UNKNOWN && srs.srid != SRID_UNKNOWN)
@@ -1841,6 +1882,8 @@ static LWGEOM* parse_gml_coll(xmlNodePtr xnode, bool *hasz, int *root_srid)
 	LWGEOM *geom = NULL;
 
 	if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
+	if (xnode == NULL)
+		gml_lwpgerror("invalid GML representation", 30);
 
 	parse_gml_srs(xnode, &srs);
 	if (*root_srid == SRID_UNKNOWN && srs.srid != SRID_UNKNOWN)

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

Summary of changes:
 NEWS                    |  1 +
 postgis/lwgeom_in_gml.c | 57 +++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 51 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list