Skip to content

Commit

Permalink
GMLAS: fix crash when reading CityGML files (fixes r-spatial/sf#2371)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Apr 1, 2024
1 parent 2a55616 commit 9485ab4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions autotest/ogr/data/gmlas/citygml_empty_lod1.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<core:CityModel xmlns:bldg="http://www.opengis.net/citygml/building/1.0" xmlns:gml="http://www.opengis.net/gml" xmlns:core="http://www.opengis.net/citygml/1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/citygml/building/1.0 http://repository.gdi-de.org/schemas/adv/citygml/building/1.0/buildingLoD1.xsd http://www.opengis.net/citygml/1.0 http://repository.gdi-de.org/schemas/adv/citygml/1.0/cityGMLBaseLoD1.xsd">
</core:CityModel>
19 changes: 19 additions & 0 deletions autotest/ogr/ogr_gmlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3449,3 +3449,22 @@ def test_ogr_gmlas_get_gml_and_iso_schemas(tmp_path):
],
)
assert ds


###############################################################################
# Test bugfix for https://github.com/r-spatial/sf/issues/2371


@pytest.mark.require_curl()
def test_ogr_gmlas_bugfix_sf_2371():

url = (
"http://repository.gdi-de.org/schemas/adv/citygml/building/1.0/buildingLoD1.xsd"
)
conn = gdaltest.gdalurlopen(url, timeout=4)
if conn is None:
pytest.skip(f"cannot open {url}")

ds = gdal.OpenEx("GMLAS:data/gmlas/citygml_empty_lod1.gml")
lyr = ds.GetLayerByName("address1")
assert lyr.GetFeatureCount() == 0
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/gmlas/ogrgmlaslayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,8 @@ bool OGRGMLASLayer::InitReader()
{
CPLAssert(m_poReader == nullptr);

m_poReader = m_poDS->CreateReader(m_fpGML);
m_bLayerDefnFinalized = true;
m_poReader = m_poDS->CreateReader(m_fpGML);
if (m_poReader != nullptr)
{
m_poReader->SetLayerOfInterest(this);
Expand Down

0 comments on commit 9485ab4

Please sign in to comment.