[SCM] PostGIS branch master updated. 3.5.0-373-gef795d36e
git at osgeo.org
git at osgeo.org
Thu Jun 5 12:44:56 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, master has been updated
via ef795d36e59dad991e0af66802f973fd6bb324b1 (commit)
from b9f1c4c6876b7d6bbeb457edf4feac11be48c920 (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 ef795d36e59dad991e0af66802f973fd6bb324b1
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Thu Jun 5 12:44:51 2025 -0700
Remove crash when using xlink without a gml prefix, references #5912
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)
diff --git a/regress/core/in_gml.sql b/regress/core/in_gml.sql
index cfdb1b5a3..d676ef688 100644
--- a/regress/core/in_gml.sql
+++ b/regress/core/in_gml.sql
@@ -996,6 +996,9 @@ SELECT 'xlink_22', ST_AsEWKT(ST_GeomFromGML('<gml:MultiGeometry xmlns:gml="http:
-- ERROR circular ref
SELECT 'xlink_23', ST_AsEWKT(ST_GeomFromGML('<gml:MultiGeometry gml:id="mg1" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink"><gml:geometryMember><gml:Point><gml:pos>1 2</gml:pos></gml:Point></gml:geometryMember><gml:geometryMember><gml:MultiGeometry xlink:type="simple" xlink:href="#mg1"/></gml:geometryMember></gml:MultiGeometry>'));
+-- XLink no gml namespace
+SELECT 'xlink_1_no_ns', ST_AsEWKT(ST_GeomFromGML('<LineString xmlns:xlink="http://www.w3.org/1999/xlink"><pointProperty><Point id="p1"><pos>1 2</pos></Point></pointProperty><pointProperty><Point xlink:type="simple" xlink:href="#p1"/></pointProperty><pos>3 4</pos></LineString>'));
+
--
-- Bijective PostGIS GML test
--
diff --git a/regress/core/in_gml_expected b/regress/core/in_gml_expected
index 556f58ce3..1bd48ba70 100644
--- a/regress/core/in_gml_expected
+++ b/regress/core/in_gml_expected
@@ -332,6 +332,7 @@ xlink_20|GEOMETRYCOLLECTION(MULTIPOLYGON(((1 2,3 4,5 6,1 2))),MULTIPOLYGON(((1 2
xlink_21|GEOMETRYCOLLECTION(MULTIPOLYGON(((1 2,3 4,5 6,1 2))),MULTIPOLYGON(((1 2,3 4,5 6,1 2))))
xlink_22|GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(1 2)),GEOMETRYCOLLECTION(POINT(1 2)))
ERROR: invalid GML representation
+xlink_1_no_ns|LINESTRING(1 2,1 2,3 4)
gml_1|POINT(1 2)
gml_2|POINT(1 2 3)
gml_3|SRID=27582;POINT(1 2)
-----------------------------------------------------------------------
Summary of changes:
postgis/lwgeom_in_gml.c | 57 ++++++++++++++++++++++++++++++++++++++------
regress/core/in_gml.sql | 3 +++
regress/core/in_gml_expected | 1 +
3 files changed, 54 insertions(+), 7 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list