On Thu, 14 Nov 2024 08:08:08 GMT, David Holmes <[email protected]> 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.
>
> 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.
alignLength is a very small value, which is an int, but alignEnd needs to be a
long. Here, changing alignLength to a long can avoid alignEnd overflow.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22095#discussion_r1841800097