Skip to content

convolve_2d: missing _validate_raster on input #1389

@brendancol

Description

@brendancol

Summary

convolve_2d() in xrspatial/convolution.py doesn't validate its input before handing it to the backend kernel. Pass a boolean, string, or complex-dtype DataArray and you get a numba TypingError or a cupy crash instead of a ValueError that says what went wrong.

Cat 6 (input validation) finding deferred from PR #1243 (issue #1241).

Reproducer

import numpy as np
import xarray as xr
from xrspatial.convolution import convolve_2d, circle_kernel

agg = xr.DataArray(np.ones((10, 10), dtype=bool))
kernel = circle_kernel(1, 1, 2)
convolve_2d(agg.data, kernel)  # numba TypingError, not ValueError

Expected

A ValueError from _validate_raster naming the function and the bad dtype. PR #1384 already taught _validate_raster to reject complex dtypes, so one call covers boolean, string, and complex.

Fix

Call _validate_raster(xr.DataArray(data), func_name='convolve_2d', ndim=2) at the top of convolve_2d(), before the kernel runs.

Severity

MEDIUM. No exploit path; just confusing errors at the API boundary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions