fix: prevent int32 overflow in box_iou - #2485
Merged
Merged
Conversation
Nikhi00718
marked this pull request as ready for review
August 11, 2026 07:33
Borda
previously approved these changes
Aug 11, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 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:
|
Contributor
There was a problem hiding this comment.
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.
Nikhi00718
force-pushed
the
fix/box-iou-int32-overflow
branch
from
August 11, 2026 14:34
012e54e to
cfade13
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes incorrect scalar IoU and IoS calculations for large
int32bounding boxes.sv.box_iounow promotes box coordinates tofloat64before computing areas. This prevents integer overflow and aligns its behavior withsv.box_iou_batch.Reproduction
For two
60000 ? 60000int32boxes 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:1 / 31 / 2Changes
float64before overlap arithmetic.int32inputs.Validation
uv run pytest --cov=supervision? 3568 passed, 20 skippeduv run pre-commit run --all-files? passedpython -m uv run pytest tests/detection/utils/test_iou_and_nms.py -q? 212 passedAI 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.