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.
Description
Two MEDIUM-severity gaps in
xrspatial.pathfinding:Cat 6 - missing
_validate_rastera_star_search(pathfinding.py:897-898) andmulti_stop_search(pathfinding.py:1373-1374) only checksurface.ndim != 2. Non-DataArray inputs raiseAttributeError; non-numeric dtypes fail inside numba with confusing errors.Cat 1 - uncapped waypoints
multi_stop_searchdoes not boundlen(waypoints):_optimize_waypoint_orderbuilds anO(N^2)distance matrix and runsN^2A* calls._nearest_neighbor_2optisO(N^3).Expected behavior
a_star_searchandmulti_stop_searchcall_validate_raster(surface, ...)to surface a cleanTypeError/ValueErrorfor bad input.multi_stop_searchenforces a maximum waypoint count.Proposed fix
_validate_raster(surface, func_name=..., name='surface', ndim=2)at the top of each function.len(waypoints)at a documented maximum (e.g._MAX_WAYPOINTS = 1000) and raiseValueErrorwith a message naming the cap when exceeded. Also validate the friction DataArray when supplied.