Skip to content

pathfinding: missing _validate_raster on surface; multi_stop_search uncapped waypoints #1439

@brendancol

Description

@brendancol

Description

Two MEDIUM-severity gaps in xrspatial.pathfinding:

Cat 6 - missing _validate_raster
a_star_search (pathfinding.py:897-898) and multi_stop_search (pathfinding.py:1373-1374) only check surface.ndim != 2. Non-DataArray inputs raise AttributeError; non-numeric dtypes fail inside numba with confusing errors.

Cat 1 - uncapped waypoints
multi_stop_search does not bound len(waypoints):

  • _optimize_waypoint_order builds an O(N^2) distance matrix and runs N^2 A* calls.
  • _nearest_neighbor_2opt is O(N^3).
  • Pathological waypoint lists cause extreme CPU consumption (DoS).

Expected behavior

  • a_star_search and multi_stop_search call _validate_raster(surface, ...) to surface a clean TypeError / ValueError for bad input.
  • multi_stop_search enforces a maximum waypoint count.

Proposed fix

  • Add _validate_raster(surface, func_name=..., name='surface', ndim=2) at the top of each function.
  • Cap len(waypoints) at a documented maximum (e.g. _MAX_WAYPOINTS = 1000) and raise ValueError with a message naming the cap when exceeded. Also validate the friction DataArray when supplied.

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