Skip to content

COG window refuses a tiled GeoTIFF whose first IFD sits past 2 GiB (OpenGeoHub GEDTM30 layers) #2569

Closed

Description

@elpidioassinaturas

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

  1. 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}
    
  2. It fails with "the GeoTIFF's header is too large or too scattered to read in place".

  3. GDAL reads the same file: gdallocationinfo -valonly -wgs84 /vsicurl/<url> -42.879 -20.754 prints 1168 (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 the a >= MAX_HEADER × 64 condition. 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 (Sparse already holds separate parts). A far IFD costs one more request, not a read of everything before it.
  • Size known: the first read's Content-Range gives the file's length. An IFD offset past that length is refused as now, as a cut-short file.
  • Test: a cog.rs test 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

Screenshots or logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions