Skip to content

Commit

Permalink
Merge pull request #9379 from rouault/fix_9352
Browse files Browse the repository at this point in the history
ERS: avoid 'Attempt at recursively opening ERS dataset' when the .ers file references a .ecw (fixes #9352)
  • Loading branch information
rouault authored Mar 5, 2024
2 parents fe3cf27 + 717f746 commit d7075c8
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 d7075c8

Please sign in to comment.