Skip to content

geotiff: reject empty rasters at write time#2078

Merged
brendancol merged 2 commits into
mainfrom
issue-2075
May 18, 2026
Merged

geotiff: reject empty rasters at write time#2078
brendancol merged 2 commits into
mainfrom
issue-2075

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #2075.

Summary

  • to_geotiff used to accept arrays whose spatial height or width was zero, write a TIFF whose IFD claimed shape (0, N) or (N, 0), and surface the error only at read time as a generic "Invalid image dimensions".
  • Add _validate_writer_spatial_shape to _validation.py. Call it from to_geotiff, write, and write_streaming so all three entry points fail closed at write time with a message that names the offending dim and points at clip/window operations as the common cause.

Backend coverage

  • numpy: validated in to_geotiff and in write (the eager backend the numpy path reaches).
  • cupy: validated in to_geotiff (which dispatches to write_geotiff_gpu); the empty-shape check fires before any GPU work starts.
  • dask+numpy and dask+cupy: validated in to_geotiff and in write_streaming (the streaming entry point both dask backends reach).

Test plan

  • New test file test_to_geotiff_empty_shape_2075.py covers shapes (0, 5), (5, 0), (0, 0) for numpy and one dask shape for the streaming path.
  • Each test asserts ValueError, that the message names the empty dim, and that no file was created on disk.
  • pytest xrspatial/geotiff/tests/ xrspatial/tests/test_geotiff*.py passes (the 8 pre-existing GPU-test failures on main are unrelated).

Writers accepted zero-height or zero-width arrays and produced TIFFs
that failed to open. Validate positive spatial shape in both the eager
and streaming entry points so the failure happens at write time with a
specific message instead of a generic "Invalid image dimensions" at
read time.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 18, 2026
Follow-up to PR review: the GPU writer is a public entry point and
direct callers (with cupy.ndarray or raw numpy) skip the to_geotiff
guard. Add the same _validate_writer_spatial_shape call before any
GPU work starts. Thread an entry_point kwarg through the helper so the
error message names the function the caller actually invoked instead
of always saying "to_geotiff". Drop an unused local in the helper.
@brendancol brendancol merged commit 096b766 into main May 18, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_geotiff writes invalid TIFF for zero-height/zero-width arrays instead of failing closed

1 participant