mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8331655: ClassFile API ClassCastException with verbose output of certain class files
Reviewed-by: psandoz
This commit is contained in:
parent
36c9607f66
commit
c1a164528a
2 changed files with 13 additions and 15 deletions
|
@ -391,21 +391,10 @@ public final class ClassReaderImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractPoolEntry.Utf8EntryImpl utf8EntryByIndex(int index) {
|
public AbstractPoolEntry.Utf8EntryImpl utf8EntryByIndex(int index) {
|
||||||
if (index <= 0 || index >= constantPoolCount) {
|
if (entryByIndex(index, TAG_UTF8, TAG_UTF8) instanceof AbstractPoolEntry.Utf8EntryImpl utf8) {
|
||||||
throw new ConstantPoolException("Bad CP UTF8 index: " + index);
|
return utf8;
|
||||||
}
|
}
|
||||||
PoolEntry info = cp[index];
|
throw new ConstantPoolException("Not a UTF8 - index: " + index);
|
||||||
if (info == null) {
|
|
||||||
int offset = cpOffset[index];
|
|
||||||
int tag = readU1(offset);
|
|
||||||
final int q = offset + 1;
|
|
||||||
if (tag != TAG_UTF8) throw new ConstantPoolException("Not a UTF8 - index: " + index);
|
|
||||||
AbstractPoolEntry.Utf8EntryImpl uinfo
|
|
||||||
= new AbstractPoolEntry.Utf8EntryImpl(this, index, buffer, q + 2, readU2(q));
|
|
||||||
cp[index] = uinfo;
|
|
||||||
return uinfo;
|
|
||||||
}
|
|
||||||
return (AbstractPoolEntry.Utf8EntryImpl) info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8320360 8330684 8331320
|
* @bug 8320360 8330684 8331320 8331655
|
||||||
* @summary Testing ClassFile limits.
|
* @summary Testing ClassFile limits.
|
||||||
* @run junit LimitsTest
|
* @run junit LimitsTest
|
||||||
*/
|
*/
|
||||||
|
@ -36,6 +36,7 @@ import java.lang.classfile.ClassFile;
|
||||||
import java.lang.classfile.Opcode;
|
import java.lang.classfile.Opcode;
|
||||||
import java.lang.classfile.attribute.CodeAttribute;
|
import java.lang.classfile.attribute.CodeAttribute;
|
||||||
import java.lang.classfile.constantpool.ConstantPoolException;
|
import java.lang.classfile.constantpool.ConstantPoolException;
|
||||||
|
import java.lang.classfile.constantpool.IntegerEntry;
|
||||||
import jdk.internal.classfile.impl.DirectMethodBuilder;
|
import jdk.internal.classfile.impl.DirectMethodBuilder;
|
||||||
import jdk.internal.classfile.impl.LabelContext;
|
import jdk.internal.classfile.impl.LabelContext;
|
||||||
import jdk.internal.classfile.impl.UnboundAttribute;
|
import jdk.internal.classfile.impl.UnboundAttribute;
|
||||||
|
@ -106,6 +107,14 @@ class LimitsTest {
|
||||||
0, 0, 0, 0, 0, 2, ClassFile.TAG_METHODREF, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}).thisClass());
|
0, 0, 0, 0, 0, 2, ClassFile.TAG_METHODREF, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}).thisClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testInvalidUtf8Entry() {
|
||||||
|
var cp = ClassFile.of().parse(new byte[]{(byte)0xCA, (byte)0xFE, (byte)0xBA, (byte)0xBE,
|
||||||
|
0, 0, 0, 0, 0, 3, ClassFile.TAG_INTEGER, 0, 0, 0, 0, ClassFile.TAG_NAMEANDTYPE, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}).constantPool();
|
||||||
|
assertTrue(cp.entryByIndex(1) instanceof IntegerEntry); //parse valid int entry first
|
||||||
|
assertThrows(ConstantPoolException.class, () -> cp.entryByIndex(2));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInvalidLookupSwitch() {
|
void testInvalidLookupSwitch() {
|
||||||
assertThrows(IllegalArgumentException.class, () ->
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue