Skip to content

More input checks for roi ops - #9684

Merged
NicolasHug merged 2 commits into
pytorch:mainfrom
NicolasHug:roifixes
Sep 29, 2026
Merged

NicolasHug merged 2 commits into
pytorch:mainfrom
NicolasHug:roifixes

Conversation

@NicolasHug

Copy link
Copy Markdown
Member

No description provided.

@pytorch-bot

pytorch-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9684

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 7e05b8d with merge base 094310d (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@NicolasHug
NicolasHug merged commit 6da25ff into pytorch:main Sep 29, 2026
44 checks passed
@NicolasHug
NicolasHug deleted the roifixes branch September 29, 2026 12:04
ousamabenyounes added a commit to ousamabenyounes/vision that referenced this pull request Oct 19, 2026
Resolve the conflict with pytorch#9684 in roi_align_kernel.cpp: keep the new
batch index range check (it already rejects a non-finite batch index
before the int cast) and guard only the four coordinates with
std::isfinite after it. Move the batch index column out of the
coordinate regression test into a test asserting the range check error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ousamabenyounes added a commit to ousamabenyounes/vision that referenced this pull request Oct 19, 2026
Finite float16 coordinates can still overflow to an infinite ROI size,
either through x2 - x1 or through the spatial_scale product, and reach
the same NaN sample points and garbage int cast. Checking the computed
ROI width and height covers both non-finite coordinates and overflow.
Drop the batch index test: that case is now rejected by the range check
added in pytorch#9684 and already covered by its tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
NicolasHug added a commit to NicolasHug/vision that referenced this pull request Nov 3, 2026
pytorch#9684 added a check that the roi_align sampling grid
(grid_h * grid_w * pooled_h * pooled_w) fits in an int, because the product
sizes the pre_calc buffer: a large sampling_ratio (or a large RoI in adaptive
mode) wraps it and leads to an out-of-bounds write. The quantized CPU kernel
(qroi_align) has the same buffer and was not covered. This adds the same check there.

It also moves the check in roi_align above the `count` computation, since
`roi_bin_grid_h * roi_bin_grid_w` can already overflow (signed overflow is UB,
and UBSan flags it) before the check runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant