Skip to content

GeoTIFF write: NaN cells in a UInt8 raster without no-data are saved as 0 with no notice #2665

Closed

Description

@giswqs

crates/data/src/raster/geotiff.rs: on the write path, fits_bytes accepts non-finite cells (!r.is_valid(v)) even when the raster has no no-data value, and the bytes closure in encode then writes them as nodata.unwrap_or(0). So a UInt8 or categorical raster with NaN cells and no no-data value is saved with those cells as 0, with no notice and no GDAL_NODATA tag. That is silent data loss under AGENTS.md's never-silent rule, so it shouldn't wait for a release quality pass.

The write_all fallback already guards this case (marked: r.nodata.is_some() || r.is_valid(v) in as_bytes); fits_bytes should do the same, so such a raster is written in a wider type (or with a no-data value and a notice) instead of becoming 0.

  • fits_bytes refuses non-finite cells when the raster has no no-data value
  • Regression test: a UInt8 raster with NaN cells and no no-data value round-trips without turning them into 0 (or says so); a clean UInt8 raster gives no notice

From: #2650 review, found during the 2026-11 release quality sweep.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions