RFR: 8344168: Change Unsafe base offset from int to long
David Holmes
dholmes at openjdk.org
Thu Nov 14 08:20:21 UTC 2024
On Thu, 14 Nov 2024 05:32:34 GMT, Shaojin Wen <swen at openjdk.org> wrote:
> The type of the Unsafe base offset constant is int, which may cause overflow when adding int offsets, such as 8343925 (PR #22012). 8343984 (PR #22027) fixes most of the offset overflows in JDK, but ArraysSupport and CRC32C are still unfixed.
>
> @liach proposed the idea of changing the Unsafe base offset to long, which is a complete solution to the Unsafe offset overflow. After discussing with @liach, I submitted this PR to implement @liach's idea.
Looking at this I'm not at all convinced this is the right thing to do. The `ARRAY_BYTE_BASE_OFFSET` is a small value - it is an `int`.
I understand there is concern about integer arithmetic overflow, but I'm not convinced this is where it needs to be addressed.
src/java.base/share/classes/java/util/zip/CRC32C.java line 227:
> 225: long alignLength
> 226: = (8 - ((Unsafe.ARRAY_BYTE_BASE_OFFSET + off) & 0x7)) & 0x7;
> 227: for (long alignEnd = off + alignLength; off < alignEnd; off++) {
I think casting the (now) long expression back to `int` makes more sense here.
-------------
PR Review: https://git.openjdk.org/jdk/pull/22095#pullrequestreview-2435312059
PR Review Comment: https://git.openjdk.org/jdk/pull/22095#discussion_r1841736158
More information about the core-libs-dev
mailing list