onnxruntime
9883e93d - contrib: add mask/input shape consistency checks in MaxpoolWithMask::Compute (#28223)

Commit
130 days ago
contrib: add mask/input shape consistency checks in MaxpoolWithMask::Compute (#28223) ### Description Replaces the long-standing `// TODO: fix this checker later` comment in `MaxpoolWithMask::Compute` with real input validation. Without these checks, a mismatched mask silently causes out-of-bounds memory access. **Changes:** - **`contrib_ops/cpu/maxpool_with_mask.h`** — Added three `ORT_RETURN_IF_NOT` guards: - Mask must have the same number of dimensions as the input tensor - Mask N and C dimensions must be nonzero when input is non-empty (prevents modulo-by-zero in `total_mask_channels`) - Each spatial dimension (dim ≥ 2) of the mask must match the corresponding input dimension - **`test/contrib_ops/maxpool_mask_test.cc`** — Added three failure-case tests: - `MaxPoolWithMask_SpatialDimMismatch` — mask spatial dims differ from input - `MaxPoolWithMask_DimCountMismatch` — mask rank differs from input rank - `MaxPoolWithMask_MaskEmptyBatchDim` — mask N=0 with non-empty input triggers the nonzero N/C guard ### Motivation and Context The mask tensor is indexed using the input's spatial step size (`x_step = height * width`, etc.), so a shape mismatch leads to silent out-of-bounds reads. Additionally, `total_mask_channels = m_shape[0] * m_shape[1]` is used as a modulo divisor in the per-channel offset formula; if either dimension is zero while the input is non-empty, this causes undefined behaviour (division by zero). The original code had a commented-out check with a `TODO` acknowledging this gap; this PR closes it. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com> Co-authored-by: Xavier Dupré <xadupre@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Xavier Dupré <xadupre@microsoft.com>
Author
Parents
Loading