Skip to content

geotiff: validate overview_level type#2079

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

geotiff: validate overview_level type#2079
brendancol merged 2 commits into
mainfrom
issue-2074

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #2074

Summary

  • Validate overview_level at the open_geotiff entry point: must be int or None, with bool rejected explicitly (Python treats bool as a subclass of int, so without this guard overview_level=True silently selected overview level 1).
  • Add the same guard inside select_overview_ifd for defense in depth: dask, GPU, and accessor readers forward overview_level to this selector directly, so a uniform TypeError is raised regardless of entry point.
  • Error message names both the rejected type and the offending value to make caller-side debugging easy.

Test plan

  • New test_overview_level_type_validation_2074.py covers bool (True/False), str, float, plus the still-working int(0), int(1), and None cases.
  • All 360 existing overview-related tests in the geotiff suite still pass.
  • Full xrspatial/geotiff/ suite: 3849 pass; 2 pre-existing failures unrelated to this change (test_predictor2_big_endian_gpu_1517, test_size_param_validation_gpu_vrt_1776) reproduce on main as well.

overview_level was compared numerically with no type check, so True
was coerced to 1 and silently returned the first overview level, and
non-int types leaked raw TypeErrors from internal comparison or list
indexing. Validate at the open_geotiff entry point and at the internal
select_overview_ifd selector (defense in depth for the dask/GPU/accessor
readers that forward the kwarg) and raise a TypeError that names the
offending type and value.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 18, 2026
)

Review feedback: the previous isinstance(int) check rejected
numpy.integer values like np.int64(1), which is inconsistent with
_validate_tile_size and friends in _validation.py. Move the check into
a shared _validate_overview_level_arg helper that accepts (int,
np.integer) and rejects bool, then call it from both open_geotiff and
select_overview_ifd so the two copies cannot drift. Add tests for
np.int64 / np.int32 at levels 0 and 1.
@brendancol brendancol merged commit 8c377ac 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.

open_geotiff overview_level accepts bool and non-int types, returning wrong resolution silently

1 participant