RFR: 8331655: ClassFile API ClassCastException with verbose output of certain class files

Paul Sandoz psandoz at openjdk.org
Fri May 3 16:27:51 UTC 2024


On Fri, 3 May 2024 15:28:05 GMT, Adam Sotona <asotona at openjdk.org> wrote:

> Specifically corrupted constant pool of a class file can cause ClassCastException, when the entries are accessed by Class-File API in exact order.
> 
> This fix avoids the ClassCastException and throws ConstantPoolException instead.
> Test is attached.
> 
> Please review.
> 
> Thanks,
> Adam

src/java.base/share/classes/jdk/internal/classfile/impl/ClassReaderImpl.java line 402:

> 400:             int tag = readU1(offset);
> 401:             final int q = offset + 1;
> 402:             if (tag == TAG_UTF8) {

Can we call into the tag accepting entryByIndex? e.g.,

if (entryByIndex(index, TAG_UTF8) instanceof AbstractPoolEntry.Utf8EntryImpl utf8) {
  return ...
}
throw new ...

?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19088#discussion_r1589423345


More information about the core-libs-dev mailing list