Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERS: avoid 'Attempt at recursively opening ERS dataset' when the .ers file references a .ecw (fixes #9352) #9379

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading