geotiff: reject empty rasters at write time#2078
Merged
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2075.
Summary
to_geotiffused 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"._validate_writer_spatial_shapeto_validation.py. Call it fromto_geotiff,write, andwrite_streamingso 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
to_geotiffand inwrite(the eager backend the numpy path reaches).to_geotiff(which dispatches towrite_geotiff_gpu); the empty-shape check fires before any GPU work starts.to_geotiffand inwrite_streaming(the streaming entry point both dask backends reach).Test plan
test_to_geotiff_empty_shape_2075.pycovers shapes(0, 5),(5, 0),(0, 0)for numpy and one dask shape for the streaming path.ValueError, that the message names the empty dim, and that no file was created on disk.pytest xrspatial/geotiff/tests/ xrspatial/tests/test_geotiff*.pypasses (the 8 pre-existing GPU-test failures onmainare unrelated).