Skip to content

gpu dispatch flag is not fail-closed: non-bool values like gpu="False" silently select the GPU path #2819

@brendancol

Description

@brendancol

Describe the bug

The gpu flag on the GeoTIFF read and write entry points is consumed by truthiness instead of being validated as a real bool.

  • open_geotiff(..., gpu=...) branches on if gpu: at xrspatial/geotiff/__init__.py:912.
  • to_geotiff(..., gpu=...) resolves use_gpu = gpu if gpu is not None else _is_gpu_data(data) at xrspatial/geotiff/_writers/eager.py:582.

"False" is a non-empty string, so gpu="False" is truthy and selects the GPU path instead of raising. Pass a stringified bool (easy to do when a flag comes from a CLI arg, env var, or config file) and you get the opposite of what you asked for, with no error. A dispatch flag that picks the wrong backend silently is a correctness hazard in an I/O module.

Expected behavior

Validate gpu as an actual bool before any branch reads it, and raise TypeError with a clear message otherwise. The read path defaults gpu to False (bool only). The write path types it as bool | None, where None means "auto-detect from the data", so None stays valid there.

gpu="False", gpu=1, and gpu=0 should raise. gpu=True and gpu=False keep working as before.

Severity

Medium. Silent wrong-backend dispatch. Not a crash or data loss, but hard to notice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggpuCuPy / CUDA GPU supportinput-validationInput validation and error messages

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions