Fix intege overflow in _setBooleanElement in a primitive list

This commit is contained in:
Martin Dindoffer 2022-05-06 14:08:24 +02:00 committed by Vaci
parent 89d1c5722e
commit b1eadaee6c
2 changed files with 19 additions and 1 deletions

View file

@ -99,7 +99,7 @@ public class ListBuilder extends CapTableBuilder.BuilderContext {
}
protected void _setBooleanElement(int index, boolean value) {
long bitOffset = index * this.step;
long bitOffset = (long) index * this.step;
byte bitnum = (byte)(bitOffset % 8);
int position = (int)(this.ptr + (bitOffset / 8));
byte oldValue = this.segment.buffer.get(position);

View file

@ -0,0 +1,18 @@
package org.capnproto;
import org.junit.Test;
import java.nio.ByteBuffer;
public class ListBuilderTest {
@Test(expected = IndexOutOfBoundsException.class)
public void _setBooleanElementShouldNotOverflowDuringPositionOffsetCalculation() {
ByteBuffer buffer = ByteBuffer.allocate(10);
BuilderArena builderArena = new BuilderArena(new DefaultAllocator());
SegmentBuilder segmentBuilder = new SegmentBuilder(buffer, builderArena);
ListBuilder listBuilder = new ListBuilder(segmentBuilder, 0, 0, 2, 0, (short) 0);
listBuilder._setBooleanElement(Integer.MAX_VALUE, true);
}
}