Skip to content

reject int overflow of rows * columns in SparseFieldMatrix - #331

Open
dxbjavid wants to merge 1 commit into
apache:masterfrom
dxbjavid:sparsefieldmatrix-dimension-overflow
Open

dxbjavid wants to merge 1 commit into
apache:masterfrom
dxbjavid:sparsefieldmatrix-dimension-overflow

Conversation

@dxbjavid

@dxbjavid dxbjavid commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

SparseFieldMatrix computes its hash key as row * columns + column in int arithmetic, but unlike OpenMapRealMatrix its constructor never checks that the dimension product fits in an int, so a sparse matrix such as 100000 by 100000 is accepted and the key wraps for cells beyond the first 2^31. Two distinct cells can then share a key, for example setEntry(42950, 0) silently overwrites the value stored at (0, 32704), which seems worse than a failure since nothing signals the corruption. This adds the same NumberIsTooLargeException guard that MATH-679 gave OpenMapRealMatrix, along with a test that fails on master. AI tooling was used to help prepare this change.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.17%. Comparing base (f554608) to head (285c3c1).
⚠️ Report is 351 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #331      +/-   ##
============================================
+ Coverage     86.54%   87.17%   +0.62%     
+ Complexity     9787       89    -9698     
============================================
  Files           532      499      -33     
  Lines         35516    33469    -2047     
  Branches       6194     5835     -359     
============================================
- Hits          30738    29176    -1562     
+ Misses         3518     3167     -351     
+ Partials       1260     1126     -134     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants