Description
open_geotiff(..., overview_level=...) does not validate the type of overview_level. In xrspatial/geotiff/_header.py:794-808, the selector assigns level = overview_level and compares it numerically. Because bool is a subclass of int in Python, overview_level=True is coerced to 1 and the function returns overview level 1 with no error. Non-int types (str, float) leak raw TypeError messages from the internal comparison or list indexing.
Downstream code then gets a wrong-resolution array with no signal that anything was off.
Reproducer
import numpy as np
import tifffile
from xrspatial.geotiff import open_geotiff
arr = np.random.randint(0, 256, size=(64, 64), dtype=np.uint8)
half = arr[::2, ::2]
with tifffile.TiffWriter("cog.tif") as tw:
tw.write(arr, tile=(32, 32), photometric="minisblack")
tw.write(half, tile=(32, 32), photometric="minisblack", subfiletype=1)
# Bug 1: bool is silently coerced to an int level
open_geotiff("cog.tif", overview_level=True).shape # (32, 32)
open_geotiff("cog.tif", overview_level=False).shape # (64, 64)
# Bug 2: raw TypeErrors from internal comparison/indexing
open_geotiff("cog.tif", overview_level="0")
# TypeError: '<' not supported between instances of 'str' and 'int'
open_geotiff("cog.tif", overview_level=1.0)
# TypeError: list indices must be integers or slices, not float
Expected behavior
overview_level should be an int (>= 0) or None. Any other type should raise a clear TypeError that names the rejected type and value.
Source location
xrspatial/geotiff/_header.py:794-808 in select_overview_ifd. The public entrypoint is open_geotiff in xrspatial/geotiff/__init__.py:243.
Environment
xarray-spatial-contrib main, Python 3.12.
Description
open_geotiff(..., overview_level=...)does not validate the type ofoverview_level. Inxrspatial/geotiff/_header.py:794-808, the selector assignslevel = overview_leveland compares it numerically. Becauseboolis a subclass ofintin Python,overview_level=Trueis coerced to1and the function returns overview level 1 with no error. Non-int types (str,float) leak rawTypeErrormessages from the internal comparison or list indexing.Downstream code then gets a wrong-resolution array with no signal that anything was off.
Reproducer
Expected behavior
overview_levelshould be anint(>= 0) orNone. Any other type should raise a clearTypeErrorthat names the rejected type and value.Source location
xrspatial/geotiff/_header.py:794-808inselect_overview_ifd. The public entrypoint isopen_geotiffinxrspatial/geotiff/__init__.py:243.Environment
xarray-spatial-contrib
main, Python 3.12.