Skip to content

Commit

Permalink
ERS: avoid 'Attempt at recursively opening ERS dataset' when the .ers…
Browse files Browse the repository at this point in the history
… file references a .ecw (fixes OSGeo#9352)

The issue was no longer reproducible in master/3.9dev due to the
https://gdal.org/development/rfc/rfc96_deferred_plugin_loading.html
change, but was still somehow latent. This commit fixes the issue in the
3.8 branch
  • Loading branch information
rouault committed Mar 5, 2024
1 parent fe3cf27 commit 717f746
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Binary file added autotest/gdrivers/data/ers/references_ecw.ecw
Binary file not shown.
14 changes: 14 additions & 0 deletions autotest/gdrivers/data/ers/references_ecw.ers
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DatasetHeader Begin
Version = "6.2"
Name = "references_ecw.ers"
DataFile = "references_ecw.ecw"
DataSetType = Translated
DataType = Raster
ByteOrder = LSBFirst
RasterInfo Begin
CellType = Unsigned8BitInteger
NrOfLines = 512
NrOfCellsPerLine = 519
NrOfBands = 1
RasterInfo End
DatasetHeader End
10 changes: 10 additions & 0 deletions autotest/gdrivers/ers.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ def test_ers_recursive_opening():
ds.GetFileList()


###############################################################################
# Test fix for https://github.com/OSGeo/gdal/issues/9352


@pytest.mark.require_driver("ECW")
def test_ers_open_data_file_ecw():

assert gdal.Open("data/ers/references_ecw.ers")


###############################################################################
# Cleanup

Expand Down
10 changes: 5 additions & 5 deletions frmts/ers/ersdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,17 +881,18 @@ int ERSProxyRasterBand::GetOverviewCount()
GDALDataset *ERSDataset::Open(GDALOpenInfo *poOpenInfo)

{
if (!Identify(poOpenInfo) || poOpenInfo->fpL == nullptr)
return nullptr;

int &nRecLevel = GetRecLevel();
// cppcheck-suppress knownConditionTrueFalse
if (GetRecLevel())
if (nRecLevel)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Attempt at recursively opening ERS dataset");
return nullptr;
}

if (!Identify(poOpenInfo) || poOpenInfo->fpL == nullptr)
return nullptr;

/* -------------------------------------------------------------------- */
/* Ingest the file as a tree of header nodes. */
/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -1020,7 +1021,6 @@ GDALDataset *ERSDataset::Open(GDALOpenInfo *poOpenInfo)
/* -------------------------------------------------------------------- */
if (EQUAL(poHeader->Find("DataSetType", ""), "Translated"))
{
int &nRecLevel = GetRecLevel();
nRecLevel++;
poDS->poDepFile = GDALDataset::FromHandle(
GDALOpen(osDataFilePath, poOpenInfo->eAccess));
Expand Down

0 comments on commit 717f746

Please sign in to comment.