Skip to content

Reject Int-wrapping multiarray dimension products - #31

Merged
barrybecker4 merged 1 commit into
masterfrom
cursor/dimension-product-overflow-606c
Nov 8, 2026
Merged

barrybecker4 merged 1 commit into
masterfrom
cursor/dimension-product-overflow-606c

Conversation

@barrybecker4

Copy link
Copy Markdown
Member

Summary

Fixes #14

MultiDimensionalIndexer now multiplies dimension lengths as a Long (via Math.multiplyExact) and rejects products that do not fit in a signed Int. That closes the hole where values such as [65537, 65537] wrapped to a small positive size, so MultiArray could allocate and index as if only that truncated count existed.

Public APIs are unchanged (getDimensionProduct remains private; getNumValues still returns Long). The only bb4 consumer found (bb4-optimization’s NumericGlobalSampler) already assumes the grid count fits in a 32-bit int.

Test plan

  • MultiDimensionalIndexer and MultiArray reject [65537, 65537] with IllegalArgumentException
  • MultiDimensionalIndexer rejects a product that overflows Long
  • Existing multiarray construction and indexing tests still pass
Open in Web Open in Cursor 

Compute MultiDimensionalIndexer dimension products with Long
multiplyExact and fail construction when the true product does
not fit in Int, so MultiArray cannot allocate from a wrapped size.

Co-authored-by: Barry G Becker <barrybecker4@yahoo.com>
@barrybecker4
barrybecker4 merged commit 5510713 into master Nov 8, 2026
1 check passed
@barrybecker4
barrybecker4 deleted the cursor/dimension-product-overflow-606c branch November 8, 2026 14:25
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.

MultiDimensionalIndexer dimension product overflows as Int

2 participants