Repository navigation
Description
Before you start
- I searched the existing issues and did not find a duplicate.
- This is a bug report, not a usage question.
What happened?
layer.addUrl with a bbox refuses a tiled GeoTIFF whose first IFD sits near the end of the file. The error is:
https://ceph.opengeohub.org/arco/dtm/gedtmlsp_twi_m_30m_sg_20060101_20151231_go01_epsg4326_v1.2.0_srl03.tif: the GeoTIFF's header is too large or too scattered to read in place
The file is a valid tiled BigTIFF: about 1.3 million × 0.5 million cells in 2048 × 2048 tiles, with 10 overviews. GDAL 3.13 reads values from it through /vsicurl/ with a few range requests.
The cause is the position check in header_read (crates/tiles/src/cog.rs):
if rounds >= MAX_ROUNDS || have.held() >= cog::MAX_HEADER || a >= cog::MAX_HEADER.saturating_mul(64) {
return None;
}A read that starts past 2 GiB (MAX_HEADER × 64) is refused, whatever its size. In these files the first IFD and its tile index (157,000 tiles, 2.5 MB) were written at the end, after the image data. The overview IFDs are at the start. The TIFF header's first-IFD offset is 340,229,032,000 for this file.
The size limits (MAX_HEADER, MAX_ROUNDS) are not the problem: the whole header is under 5 MB. Only the position is.
This applies to most of OpenGeoHub's global layers, which are CC BY 4.0 and public with CORS:
- the GEDTM30 terrain model, v1.2;
- most of its land-surface parameters (slope, curvatures, TWI, openness and others), at 30 to 240 m.
I checked the first-IFD offsets of 87 GEDTM30 files. In 48 the header starts past 2 GB, including:
- the terrain model and its standard deviation;
- every v1.2 layer at 30 m except the hillshade.
The others have it at the start or under 2 GB and read fine, as do the OpenLandMap-soildb soil layers on the same server.
Steps to reproduce
-
In
rustgis-cli run --yes, run:layer.addUrl={"url": "https://ceph.opengeohub.org/arco/dtm/gedtmlsp_twi_m_30m_sg_20060101_20151231_go01_epsg4326_v1.2.0_srl03.tif", "bbox": [-43.0, -20.84, -42.75, -20.65], "zoom": false} -
It fails with "the GeoTIFF's header is too large or too scattered to read in place".
-
GDAL reads the same file:
gdallocationinfo -valonly -wgs84 /vsicurl/<url> -42.879 -20.754prints1168(TWI 11.68).
Expected behavior
The header is read wherever its IFDs are, within the existing limits on the bytes held (MAX_HEADER) and on the number of reads (MAX_ROUNDS).
Choices in this proposal
- Where: in
header_read, drop thea >= MAX_HEADER × 64condition. Bytes held and rounds stay bounded as now, so a file can't make the reader hold more than 32 MB of header or make more than 12 reads. - Reads: a part that starts past the bytes already held is read as its own range (
Sparsealready holds separate parts). A far IFD costs one more request, not a read of everything before it. - Size known: the first read's
Content-Rangegives the file's length. An IFD offset past that length is refused as now, as a cut-short file. - Test: a
cog.rstest builds a small tiled GeoTIFF whose first IFD comes after the tile data, at an offset past 2 GiB on a sparse in-memory reader. It checks that the layout parses and a window's tiles read.
How are you running RustGIS?
Desktop app (Windows installer), and rustgis-cli
Version
0.7.0; the check is the same on main (e4cc3ae)
Operating system, browser and graphics
Windows 11
Sample data
- Files with the header near the end:
- https://ceph.opengeohub.org/arco/dtm/gedtmlsp_twi_m_30m_sg_20060101_20151231_go01_epsg4326_v1.2.0_srl03.tif (first IFD at 340 GB)
- https://s3.opengeohub.org/global/dtm/v1.2.0/slope.in.degree_gedtm_m_30m_s_20060101_20151231_go_epsg.4326_v1.2.0.tif (308 GB)
- https://ceph.opengeohub.org/arco/dtm/gedtm_rf_m_30m_sg_20060101_20151231_go01_epsg4326_v1.2.0_srl04.tif (the terrain model itself, 432 GB)
- The same layer, older version, header at the start (reads fine): https://s3.opengeohub.org/global/dtm/v3/twi_edtm_m_30m_s_20000101_20221231_go_epsg.4326_v20241230.tif
Screenshots or logs
No response
Activity
0.1.51: propriedades do solo do OpenLandMap e derivadas do relevo do …
0.1.52: terreno da América do Sul (ANADEM) e elevação do GEDTM30, pel…
fix(tiles): a COG whose header sits past 2 GiB is read in place (open…