RFR: 8268720: Unspecified checks on NameAndType constants should not be performed

David Holmes dholmes at openjdk.java.net
Wed Jun 16 01:20:31 UTC 2021


On Tue, 15 Jun 2021 20:17:32 GMT, Harold Seigel <hseigel at openjdk.org> wrote:

> Please review this small fix for JDK-8268720.  The fix changes the JVM to no longer throw a ClassFormatError exception for a constant pool NameAndType that has a name and descriptor that are both valid, but are incompatible together, such as "<init>()D".
> 
> Note that if the CONSTANT_NameAndType_info for a CONSTANT_Methodref_info contained the name "<init>"and descriptor such as "()D" then a ClassFormatError exception would get thrown because the CONSTANT_Methodref_info would be invalid. JVM Spec section 4.4.2 says:
> 
> If the name of the method in a CONSTANT_Methodref_info structure begins with a '<' ('\u003c'), then the name must be the special name <init>, representing an instance initialization method (§2.9.1). The return type of such a method must be void.
> 
> The fix was tested with Mach5 tiers 1 and 2 on Linux, Mac OS, and Windows, Mach5 tiers 3-5 on Linux x64, and JCK Lang and VM tests on Linux x64.
> 
> Thanks, Harold

Hi Harold,

Looks good. A couple of suggested changes to comments.

Thanks,
David

src/hotspot/share/classfile/classFileParser.cpp line 714:

> 712:             } else if (!Signature::is_void_method(signature)) { // must have void return
> 713:               throwIllegalSignature("Method", name, signature, CHECK);
> 714:               return;

So this is the check that is now skipped when doing the NameAndType_info check. In which case the comment should be expanded to something like:

" ... it must be <init\> and must have a void signature"

also the comment at line 697:

// Method name and signature are verified above, when iterating NameAndType_info.

may no longer be accurate.

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

Marked as reviewed by dholmes (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/4497


More information about the hotspot-runtime-dev mailing list