Fix intege overflow in _setBooleanElement in a primitive list
This commit is contained in:
parent
89d1c5722e
commit
b1eadaee6c
2 changed files with 19 additions and 1 deletions
|
@ -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);
|
||||
|
|
18
runtime/src/test/java/org/capnproto/ListBuilderTest.java
Normal file
18
runtime/src/test/java/org/capnproto/ListBuilderTest.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue