Skip to content

Commit 6d47fc6

Browse files
committedSep 14, 2023
8313258: RuntimeInvisibleTypeAnnotationsAttribute.annotations() API Index out of Bound error
Reviewed-by: briangoetz
1 parent c7d306c commit 6d47fc6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
 

‎src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public void setLabelTarget(Label label, int bci) {
9797

9898
@Override
9999
public Label getLabel(int bci) {
100+
if (bci < 0 || bci > codeLength)
101+
throw new IllegalArgumentException(String.format("Bytecode offset out of range; bci=%d, codeLength=%d",
102+
bci, codeLength));
100103
if (labels == null)
101104
labels = new LabelImpl[codeLength + 1];
102105
LabelImpl l = labels[bci];

‎test/jdk/jdk/classfile/LimitsTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.lang.constant.ConstantDescs;
3131
import java.lang.constant.MethodTypeDesc;
3232
import jdk.internal.classfile.Classfile;
33+
import jdk.internal.classfile.impl.LabelContext;
3334
import org.junit.jupiter.api.Test;
3435
import static org.junit.jupiter.api.Assertions.*;
3536

@@ -69,4 +70,13 @@ void testEmptyCode() {
6970
assertThrows(IllegalArgumentException.class, () -> Classfile.of().build(ClassDesc.of("EmptyClass"), cb -> cb.withMethodBody(
7071
"emptyMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, cob -> {})));
7172
}
73+
74+
@Test
75+
void testCodeRange() {
76+
var cf = Classfile.of();
77+
var lc = (LabelContext)cf.parse(cf.build(ClassDesc.of("EmptyClass"), cb -> cb.withMethodBody(
78+
"aMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, cob -> cob.return_()))).methods().get(0).code().get();
79+
assertThrows(IllegalArgumentException.class, () -> lc.getLabel(-1));
80+
assertThrows(IllegalArgumentException.class, () -> lc.getLabel(10));
81+
}
7282
}

0 commit comments

Comments
 (0)
Please sign in to comment.