Skip to content

reproject: grid/bounds/precision parameters not validated #1433

@brendancol

Description

@brendancol

Description

reproject() accepts several user-controlled grid parameters that are not range-checked:

Parameter Bad input today
resolution 0 -> raw ZeroDivisionError in _grid.py:163-200; negative -> silently produces backwards coords
width / height 0 -> ZeroDivisionError; negative -> max(1, int(round(neg))) keeps a negative res_x, output is silently wrong
bounds (10, 10, 0, 0) (right < left, top < bottom) -> negative res_x, res_y -> output coords descending and downstream resampler emits all-nodata silently
transform_precision -1 -> np.linspace(0, end, 0) empty -> IndexError from _bilinear_interp_2ch indexing gr[-1]

Expected behavior

Each parameter is range-checked at the top of reproject(). Bad input raises a clean ValueError with a message naming the offending parameter.

Proposed fix

  • resolution: must be a positive finite scalar or 2-tuple of same.
  • width / height: must be a positive int.
  • bounds: must be a 4-tuple of finite floats with right > left and top > bottom.
  • transform_precision: must be a non-negative int.

merge() consumes the same resolution / bounds parameters so the same checks apply there.

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