Skip to content

Avoid integer overflow when symmetrizing ellipse matrices - #5239

Open
FlorianPfaff wants to merge 3 commits into
mainfrom
fix-ellipse-symmetrize-integer-overflow
Open

Avoid integer overflow when symmetrizing ellipse matrices#5239
FlorianPfaff wants to merge 3 commits into
mainfrom
fix-ellipse-symmetrize-integer-overflow

Conversation

@FlorianPfaff

@FlorianPfaff FlorianPfaff commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • prevent integer overflow in tracking.ellipse_geometry.symmetrize
  • scale each operand before adding it, so integer inputs are promoted before the potentially overflowing addition
  • add a focused public-API regression test

Bug

The previous implementation evaluated matrix + matrix.T in the input integer dtype and only multiplied by 0.5 afterward. For example,

matrix = np.array([[120, 100], [80, 110]], dtype=np.int8)

should symmetrize to [[120, 90], [90, 110]], but the intermediate integer addition overflowed and produced [[-8, -38], [-38, -18]].

This affects public calls such as project_symmetric_covariance() when users provide integer array-like covariance input.

Fix

Use

0.5 * matrix + 0.5 * matrix.T

which preserves the mathematical result for floating-point inputs while promoting integer operands before addition.

Testing

Added tests/tracking/test_ellipse_geometry_integer_overflow.py, which passes an int8 covariance through project_symmetric_covariance() and checks both the correct numerical result and floating-point output dtype.

@FlorianPfaff
FlorianPfaff enabled auto-merge (squash) August 6, 2026 06:12
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 25.74s
✅ JSON prettier 7 0 0 0 0.9s
✅ JSON v8r 7 0 0 3.19s
✅ MARKDOWN markdownlint 68 0 0 0 1.77s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.77s
✅ PYTHON black 1866 87 0 0 88.88s
✅ PYTHON isort 1866 139 0 0 2.73s
✅ REPOSITORY betterleaks yes no no 2.27s
✅ REPOSITORY checkov yes no no 52.28s
✅ REPOSITORY gitleaks yes no no 17.02s
✅ REPOSITORY git_diff yes no no 0.31s
✅ REPOSITORY secretlint yes no no 82.71s
✅ REPOSITORY syft yes no no 6.07s
✅ REPOSITORY trivy-sbom yes no no 5.66s
✅ REPOSITORY trufflehog yes no no 31.28s
✅ YAML prettier 11 0 0 0 0.77s
✅ YAML v8r 11 0 0 11.01s
✅ YAML yamllint 11 0 0 0.53s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@9.6.0 --custom-flavor-setup --custom-flavor-linters PYTHON_BLACK,PYTHON_ISORT,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_GITLEAKS,REPOSITORY_BETTERLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

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.

1 participant