On Thu, 20 Aug 2026 10:31:55 GMT, Per Minborg <[email protected]> wrote:
>> This PR proposes to introduce checks for multiplication overflow in >> `SequenceLayoutImpl`. >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Per Minborg has updated the pull request incrementally with one additional > commit since the last revision: > > Use Math.multiplyExact on yet another place src/java.base/share/classes/jdk/internal/foreign/layout/SequenceLayoutImpl.java line 146: > 144: long inferredCount = expectedCount / actualCount; > 145: elementCounts[inferPosition] = inferredCount; > 146: actualCount = Math.multiplyExact(actualCount, inferredCount); The `ArithmeticException` thrown here should also be translated into an IAE I suppose. src/java.base/share/classes/jdk/internal/foreign/layout/SequenceLayoutImpl.java line 181: > 179: MemoryLayout elemLayout = elementLayout(); > 180: while (elemLayout instanceof SequenceLayoutImpl elemSeq) { > 181: count = Math.multiplyExact(count ,elemSeq.elementCount()); Same here, but `flatten` is not specified to throw any exception right now. That seems like something we should fix as well (not sure if this PR is the right place for it though). ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/32191#discussion_r3821114831 PR Review Comment: https://git.openjdk.org/jdk/pull/32191#discussion_r3821122766
