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

PMTiles: fix 'Non increasing tile_id' error when opening some files (fixes #9288) #9289

Merged
merged 1 commit into from
Feb 26, 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 not shown.
12 changes: 12 additions & 0 deletions autotest/ogr/ogr_pmtiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,15 @@ def test_ogr_pmtiles_read_corrupted_min_zoom_larger_than_30():
ds = ogr.Open(tmpfilename)
assert gdal.GetLastErrorMsg() == "Clamping max_zoom from 255 to 30"
assert ds.GetMetadataItem("ZOOM_LEVEL") == "30"


###############################################################################


def test_ogr_pmtiles_read_with_many_directories():

ds = gdal.OpenEx(
"data/pmtiles/subset7_truncated.pmtiles", open_options=["ZOOM_LEVEL=0"]
)
lyr = ds.GetLayer(0)
assert lyr.GetFeatureCount() != 0
4 changes: 3 additions & 1 deletion ogr/ogrsf_frmts/pmtiles/ogr_pmtiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ class OGRPMTilesTileIterator
int m_nCurY = -1;

// for sanity checks. Must be increasing when walking through entries
uint64_t m_nLastTileId = 0;
static constexpr uint64_t INVALID_LAST_TILE_ID =
std::numeric_limits<uint64_t>::max();
uint64_t m_nLastTileId = INVALID_LAST_TILE_ID;

// Computed values from zoom leven and min/max x/y
uint64_t m_nMinTileId = std::numeric_limits<uint64_t>::max();
Expand Down
5 changes: 3 additions & 2 deletions ogr/ogrsf_frmts/pmtiles/ogrpmtilestileiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pmtiles::entry_zxy OGRPMTilesTileIterator::GetNextTile(uint32_t *pnRunLength)
static_cast<uint8_t>(m_nZoomLevel), m_nCurX,
m_nCurY);
m_nMaxTileId = m_nMinTileId;
m_nLastTileId = 0;
m_nLastTileId = INVALID_LAST_TILE_ID;
while (m_aoStack.size() > 1)
m_aoStack.pop();
const int nMinEntryIdx = find_tile_idx_lesser_or_equal(
Expand Down Expand Up @@ -323,7 +323,8 @@ pmtiles::entry_zxy OGRPMTilesTileIterator::GetNextTile(uint32_t *pnRunLength)
break;
}

if (sContext.sEntries[0].tile_id <= m_nLastTileId)
if (m_nLastTileId != INVALID_LAST_TILE_ID &&
sContext.sEntries[0].tile_id <= m_nLastTileId)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Non increasing tile_id");
Expand Down
Loading