RFR: 8314236: Overflow in Collections.rotate

Nikita Sakharin duke at openjdk.org
Fri Sep 15 12:38:51 UTC 2023


On Mon, 14 Aug 2023 20:23:13 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> `Collections.rotate` method contains a bug. This method throws IndexOutOfBoundsException on arrays larger than $2^{30}$ elements. The way to reproduce:
>> 
>> final int size = (1 << 30) + 1;
>> final List<Byte> list = new ArrayList<>(size);
>> for (int i = 0; i < size; ++i)
>>     list.add((byte) 0);
>> Collections.rotate(list, size - 1);
>> 
>> Output:
>> ```Exception in thread "main" java.lang.IndexOutOfBoundsException: Index -2147483648 out of bounds for length 1073741825```
>> 
>> In that case private method `Collections.rotate1` will be called. And the line:
>> `i += distance;`
>> will cause overflow. I fixed this method and wrote a test for it.
>> 
>> I've signed the Oracle Contributor Agreement, but I don't have permission to raise a bug in the JDK Bug System.
>> 
>> Kindly ask you to raise a bug.
>
> Submitted: [JDK-8314236](https://bugs.openjdk.org/browse/JDK-8314236)
> 
> Please change the PR synopsis to: "8314236: Overflow in Collections.rotate".
> 
> Also go to https://github.com/nikita-sakharin/jdk/actions, and enable testing workflows.

Aleksey Shipilëv (@shipilev), Stuart Marks (@stuart-marks), thank you for your approvals. Since both reviewers approved the PR, it is ready to be integrated.

I have already executed `/integrate` command. Now I am awaiting one of you to execute `/sponsor`  command. So I kindly ask you to do that.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15270#issuecomment-1721204139


More information about the core-libs-dev mailing list