Skip to content

Commit

Permalink
8332486: ClassFile API ArrayIndexOutOfBoundsException with label meta…
Browse files Browse the repository at this point in the history
…data

Reviewed-by: psandoz
  • Loading branch information
asotona committed May 21, 2024
1 parent 5f2b8d0 commit 451cc23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ private int adjustForObjectOrUninitialized(int bci) {
}

private void inflateLabel(int bci) {
if (bci < 0 || bci > codeLength)
throw new IllegalArgumentException(String.format("Bytecode offset out of range; bci=%d, codeLength=%d",
bci, codeLength));
if (labels[bci] == null)
labels[bci] = new LabelImpl(this, bci);
}
Expand Down
17 changes: 16 additions & 1 deletion test/jdk/jdk/classfile/LimitsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 8320360 8330684 8331320 8331655 8331940
* @bug 8320360 8330684 8331320 8331655 8331940 8332486
* @summary Testing ClassFile limits.
* @run junit LimitsTest
*/
Expand All @@ -37,8 +37,11 @@
import java.lang.classfile.attribute.CodeAttribute;
import java.lang.classfile.attribute.LineNumberInfo;
import java.lang.classfile.attribute.LineNumberTableAttribute;
import java.lang.classfile.attribute.LocalVariableInfo;
import java.lang.classfile.attribute.LocalVariableTableAttribute;
import java.lang.classfile.constantpool.ConstantPoolException;
import java.lang.classfile.constantpool.IntegerEntry;
import java.lang.classfile.instruction.LocalVariable;
import java.util.List;
import jdk.internal.classfile.impl.DirectCodeBuilder;
import jdk.internal.classfile.impl.DirectMethodBuilder;
Expand Down Expand Up @@ -175,4 +178,16 @@ void testLineNumberOutOfBounds() {
.writeAttribute(LineNumberTableAttribute.of(List.of(LineNumberInfo.of(500, 0))))
))).methods().get(0).code().get().elementList());
}

@Test
void testLocalVariableOutOfBounds() {
assertThrows(IllegalArgumentException.class, () ->
ClassFile.of().parse(ClassFile.of().build(ClassDesc.of("LocalVariableClass"), cb -> cb.withMethodBody(
"localVariableMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, cob -> ((DirectCodeBuilder)cob
.return_())
.writeAttribute(LocalVariableTableAttribute.of(List.of(
new UnboundAttribute.UnboundLocalVariableInfo(0, 200,
cob.constantPool().utf8Entry("a"), cob.constantPool().utf8Entry("A"), 0))))
))).methods().get(0).code().get().elementList());
}
}

0 comments on commit 451cc23

Please sign in to comment.