Skip to content

to_geotiff accepts tile_size values that are not multiples of 16 #1767

Closed

Description

@brendancol

to_geotiff accepts tile_size values that violate the TIFF 6 spec.

The spec requires TileWidth and TileLength to be multiples of 16. The current validation in xrspatial/geotiff/__init__.py only checks that tile_size is a positive int, so tile_size=17 slips through and writes a file that the in-repo reader round-trips fine but that strict TIFF readers (GDAL, libtiff strict mode) may reject.

Reproducer:

import numpy as np
import xarray as xr
from xrspatial.geotiff import to_geotiff

da = xr.DataArray(np.zeros((32, 32), dtype="float32"), dims=("y", "x"))
to_geotiff(da, "/tmp/bad.tif", tiled=True, tile_size=17)  # writes anyway

Fix: when tiled=True, require tile_size to be a positive multiple of 16. Raise ValueError naming the bad value and suggesting the nearest valid choices ((tile_size // 16) * 16 and ((tile_size // 16) + 1) * 16). Update the docstring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinginput-validationInput validation and error messages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions