Skip to content

fix: prevent int32 overflow in box_iou - #2485

Merged
Borda merged 2 commits into
roboflow:developfrom
Nikhi00718:fix/box-iou-int32-overflow
Aug 12, 2026
Merged

fix: prevent int32 overflow in box_iou#2485
Borda merged 2 commits into
roboflow:developfrom
Nikhi00718:fix/box-iou-int32-overflow

Conversation

@Nikhi00718

@Nikhi00718 Nikhi00718 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes incorrect scalar IoU and IoS calculations for large int32 bounding boxes.

sv.box_iou now promotes box coordinates to float64 before computing areas. This prevents integer overflow and aligns its behavior with sv.box_iou_batch.

Reproduction

For two 60000 ? 60000 int32 boxes offset by 30,000 pixels, the previous scalar implementation could return an IoU greater than 1 and an IoS of 0. The corrected results are:

  • IoU: 1 / 3
  • IoS: 1 / 2

Changes

  • Promote scalar box coordinates to float64 before overlap arithmetic.
  • Add regression coverage for both IoU and IoS with large int32 inputs.
  • Add an unreleased changelog entry.

Validation

  • uv run pytest --cov=supervision ? 3568 passed, 20 skipped
  • uv run pre-commit run --all-files ? passed
  • python -m uv run pytest tests/detection/utils/test_iou_and_nms.py -q ? 212 passed

AI assistance disclosure

I identified and reproduced the issue, then used OpenAI Codex to assist with the implementation and regression-test work. I personally reviewed the resulting diff and ran the validation commands listed above to verify the fix. Any full-suite or local-environment limitations are documented in the validation section.

@Nikhi00718
Nikhi00718 marked this pull request as ready for review August 11, 2026 07:33
@Nikhi00718
Nikhi00718 requested a review from SkalskiP as a code owner August 11, 2026 07:33
@CLAassistant

CLAassistant commented Aug 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Borda
Borda requested a balanced review from Copilot August 11, 2026 13:54
Borda
Borda previously approved these changes Aug 11, 2026
@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88%. Comparing base (803378d) to head (37b387b).

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2485   +/-   ##
=======================================
  Coverage       88%     88%           
=======================================
  Files           85      85           
  Lines        12042   12048    +6     
=======================================
+ Hits         10561   10567    +6     
  Misses        1481    1481           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Prevents int32 overflow in scalar box overlap calculations.

Changes:

  • Promotes scalar coordinates to float64.
  • Adds IoU and IoS regression tests.
  • Documents the fix in the changelog.

Assessment: Code quality 4/5 · Testing 5/5 · Documentation 5/5

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/supervision/detection/utils/iou_and_nms.py Adds safe coordinate promotion.
tests/detection/utils/test_iou_and_nms.py Covers large int32 boxes.
docs/changelog.md Records the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/supervision/detection/utils/iou_and_nms.py Outdated
Borda
Borda previously approved these changes Aug 12, 2026
- Preserve integer coordinate differences before floating-point area arithmetic.
- Add 2**53 IoU/IoS regressions and reject complex coordinates.

---

Co-authored-by: Codex <codex@openai.com>
@Borda
Borda merged commit d2aa06b into roboflow:develop Aug 12, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants