Skip to content

8333812: ClassFile.verify() can throw exceptions instead of returning VerifyErrors #20241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

asotona
Copy link
Member

@asotona asotona commented Jul 18, 2024

ClassFile.verify() should always return list of verification errors and never throw an exception, even for corrupted classes.
BoundAttribute initializations of LocalVariableTable and LocalVariableTypeTable attributes do not expect invalid possible locations and cause ClassCastException.

This patch fixes BoundAttribute to throw IllegalArgumentException for invalid LocalVariableTable and LocalVariableTypeTable attributes locations. And makes VerifierImpl a bit more resilient to exceptions thrown from the verifier initialization.

Relevant test is added.

Please review.

Thanks,
Adam


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8333812: ClassFile.verify() can throw exceptions instead of returning VerifyErrors (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20241/head:pull/20241
$ git checkout pull/20241

Update a local copy of the PR:
$ git checkout pull/20241
$ git pull https://git.openjdk.org/jdk.git pull/20241/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20241

View PR using the GUI difftool:
$ git pr show -t 20241

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20241.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 18, 2024

👋 Welcome back asotona! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jul 18, 2024

@asotona This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8333812: ClassFile.verify() can throw exceptions instead of returning VerifyErrors

Reviewed-by: liach

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 17 new commits pushed to the master branch:

  • 84bc476: 8336258: Document the behavior of 'exclude' and 'compileonly' with respect to inlining
  • 5d965f3: 8336466: C2: Parser incorrectly/unnecessarily checks for clinits
  • b703be9: 8336465: C2: EA incorrectly/unnecessarily checks for clinits
  • 0ddf54e: 8335709: C2: assert(!loop->is_member(get_loop(useblock))) failed: must be outside loop
  • 10982fe: 8335843: C2 hits assert(_print_inlining_stream->size() > 0) failed: missing inlining msg
  • fa5ad70: 8334771: [TESTBUG] Run TestDockerMemoryMetrics.java with -Xcomp fails exitValue = 137
  • 10fcad7: 8325945: Error reporting should limit the number of String characters printed
  • f5871df: 8336675: Remove UnixFileSystemProvider.checkPath in favor of UnixPath.toUnixPath
  • 902bada: 8234071: JTable.AUTO_RESIZE_LAST_COLUMN acts like AUTO_RESIZE_ALL_COLUMNS
  • 1b9270a: 8328723: IP Address error when client enables HTTPS endpoint check on server socket
  • ... and 7 more: https://git.openjdk.org/jdk/compare/5f7b0072cfe7434b43dea53b2a8d55c56c6668ea...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 18, 2024
@openjdk
Copy link

openjdk bot commented Jul 18, 2024

@asotona The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Jul 18, 2024
@mlbridge
Copy link

mlbridge bot commented Jul 18, 2024

Webrevs

@@ -114,9 +114,10 @@ public static List<VerifyError> verify(ClassModel classModel, Consumer<String> l
}

public static List<VerifyError> verify(ClassModel classModel, ClassHierarchyResolver classHierarchyResolver, Consumer<String> logger) {
var klass = new VerificationWrapper(classModel);
log_info(logger, "Start class verification for: %s", klass.thisClassName());
String clsName = classModel.thisClass().asInternalName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can still throw ConstantPoolException if this_class points to a non-Class entry. This entry is lazily read by ClassReader, so you can create a ClassModel for such a bad class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, a malformed Class constant can point to a non-utf8, so the asInternalName can fail too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it will still throw if you pass a broken model to ClassFile::verify(ClassModel).
I'll catch this top-level exception in both ClassFile::verify methods.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 19, 2024
@asotona
Copy link
Member Author

asotona commented Jul 19, 2024

Thank you.

/integrate

@openjdk
Copy link

openjdk bot commented Jul 19, 2024

Going to push as commit c25c489.
Since your change was applied there have been 18 commits pushed to the master branch:

  • 6e9fcc2: 8336816: runtime/PrintingTests/StringPrinting.java fails with release VMs
  • 84bc476: 8336258: Document the behavior of 'exclude' and 'compileonly' with respect to inlining
  • 5d965f3: 8336466: C2: Parser incorrectly/unnecessarily checks for clinits
  • b703be9: 8336465: C2: EA incorrectly/unnecessarily checks for clinits
  • 0ddf54e: 8335709: C2: assert(!loop->is_member(get_loop(useblock))) failed: must be outside loop
  • 10982fe: 8335843: C2 hits assert(_print_inlining_stream->size() > 0) failed: missing inlining msg
  • fa5ad70: 8334771: [TESTBUG] Run TestDockerMemoryMetrics.java with -Xcomp fails exitValue = 137
  • 10fcad7: 8325945: Error reporting should limit the number of String characters printed
  • f5871df: 8336675: Remove UnixFileSystemProvider.checkPath in favor of UnixPath.toUnixPath
  • 902bada: 8234071: JTable.AUTO_RESIZE_LAST_COLUMN acts like AUTO_RESIZE_ALL_COLUMNS
  • ... and 8 more: https://git.openjdk.org/jdk/compare/5f7b0072cfe7434b43dea53b2a8d55c56c6668ea...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 19, 2024
@openjdk openjdk bot closed this Jul 19, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 19, 2024
@openjdk
Copy link

openjdk bot commented Jul 19, 2024

@asotona Pushed as commit c25c489.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

try {
return VerifierImpl.verify(model, classHierarchyResolverOption().classHierarchyResolver(), null);
} catch (IllegalArgumentException verifierInitializationError) {
return List.of(new VerifyError(verifierInitializationError.getMessage()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the list returned by VerifierImpl.verify(…) is mutable, whereas List.of(…) is unmodifiable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good observation; we should check that all collection-returning APIs in ClassFile API are immutable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants