diff --git a/autotest/gdrivers/data/ers/references_ecw.ecw b/autotest/gdrivers/data/ers/references_ecw.ecw new file mode 100644 index 000000000000..ade6498f1606 Binary files /dev/null and b/autotest/gdrivers/data/ers/references_ecw.ecw differ diff --git a/autotest/gdrivers/data/ers/references_ecw.ers b/autotest/gdrivers/data/ers/references_ecw.ers new file mode 100644 index 000000000000..7c16a1b4b20d --- /dev/null +++ b/autotest/gdrivers/data/ers/references_ecw.ers @@ -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 diff --git a/autotest/gdrivers/ers.py b/autotest/gdrivers/ers.py index 82046df69d14..701580704ac9 100755 --- a/autotest/gdrivers/ers.py +++ b/autotest/gdrivers/ers.py @@ -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 diff --git a/frmts/ers/ersdataset.cpp b/frmts/ers/ersdataset.cpp index 919d64f7d4b4..d83ed19b4251 100644 --- a/frmts/ers/ersdataset.cpp +++ b/frmts/ers/ersdataset.cpp @@ -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. */ /* -------------------------------------------------------------------- */ @@ -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));