Repository navigation
fix(detections): Prevent integer aspect-ratio overflow - #2729
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2729 +/- ##
=======================================
- Coverage 94% 94% -0%
=======================================
Files 83 83
Lines 13316 13322 +6
=======================================
+ Hits 12509 12512 +3
- Misses 807 810 +3 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Integer arrays below 64-bit unnecessarily use costly object arithmetic, and the changelog metadata remains stale.
2 open findings
What changed in this PR
Fixes integer overflow in Detections.box_aspect_ratio.
Changes:
- Uses exact integer subtraction before float conversion.
- Adds boundary and compatibility tests.
- Documents the fix in the changelog.
| File | Description |
|---|---|
src/supervision/detection/core.py |
Corrects integer aspect-ratio arithmetic. |
tests/detection/test_core.py |
Adds regression and edge-case coverage. |
docs/changelog.md |
Records the behavior fix. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Changes: - Add a regression asserting that float32 corner subtraction retains its original rounding before producing float64 aspect ratios. Impact: - Prevent future integer-overflow fixes from silently promoting floating coordinates and changing existing ratios. Verification: - Detection tests: 264 passed. - Full coverage suite: 5622 passed, 97 skipped, 39 warnings; 94% coverage. - Repository-wide pre-commit, targeted format and mypy, and closure evidence checks passed. Residual limits: - The parent verified the added regression after independent QA identified it; no second independent correction review ran. - Local checks used the NumPy fallback backend; hosted cross-platform and OpenCV parity were not verified. --- Co-authored-by: Codex <codex@openai.com>
Borda
approved these changes
Oct 15, 2026
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.


Description
Detections.box_aspect_ratiocan return a negative ratio for an ordered integer box because it subtracts corners in the coordinate dtype. For example:Motivation and Context
I found this while checking aspect-ratio filtering on integer detections. Overflow in either width or height can make the filter select the wrong boxes.
box_areaalready handles the same arithmetic boundary.Changes Made
Testing
pytest tests/detection/test_core.py -q: 263 passed.pytest -q --cov=supervision: 5876 passed, six skipped, with 94% coverage after merging currentdevelop. The four signed-range regressions fail against the pristine property; the other 12 focused cases pass.pre-commit run --all-files: all hooks passed.Additional validation: 99 exact pristine/patch compatibility checks, 16 integer-range checks against Python Fraction arithmetic, and 24 previous-head parity checks for extreme, strided and read-only integer arrays.
Added/updated tests, and the full suite passes locally
Updated docs (docstrings / mkdocs entry) for new or changed public API
Added a changelog entry in
docs/changelog.mdunderUnreleased(skip for lint/type/format-only or pure doc changes)Additional Notes
The public API and stored arrays do not change. Dtype-based widening follows
get_bbox_size_category; converting corners directly to float64 would lose one-unit widths above 2**53.AI assistance disclosure: AI-assisted development tools were used during investigation and implementation. The reported tests were run against the final diff.