-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8328874: Class::forName0 should validate the class name length early #26802
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
base: master
Are you sure you want to change the base?
Conversation
Validate class name length immediately after GetStringUTFLength() in Class.forName0. This prevents potential issues caused by overly long class names before they reach later code that would reject them, throwing ClassNotFoundException early.
👋 Welcome back ghan! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
Webrevs
|
We currently have a trend of moving argument validations and checks to pure Java code, to minimize downcall into the VM (whose code cannot be optimized by compilers). Even if we keep checks in the VM, I guess jvm.cpp might be a better place than Class.c. |
No, that would defeat the purpose of creating this request in the first place. It was the calls within Class.c that originally choked on the excessive length. We want to avoid operating on these excessively large strings, and so need to bail out early on the Java/libjava side. |
fix whitespace errors
correct length of class name
@liach @dholmes-ora Thank you both for the detailed feedback and explanation. |
There is a |
Surely that loop already exists, and even if it not, it should live in a place where it is more widely useful and easier to optimize. (Widely useful? Yes, because asking the length of a string in modified-utf8, and checking whether it fits inside the constant pool limit, is not just for (Easier to optimize? If we have the loop in a common place, maintainers will probably ensure that it has the right performance characteristics. A one-off loop is less likely to attract improvements in the future.) A quick search reveals a new friend, Perhaps not for this PR, we might add a method somewhere (requires discussion) that calls Also, speaking of improvements, if such a method is framed as a constant pool validity check ( |
(Chen beat me to the discovery!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is up to core-libs folk but to me that seems far too heavyweight to have on the Java side, and we are then going to repeat some of it in the C code.
updates the class name length validation logic on the Java side
@liach @dholmes-ora @rose00 @RogerRiggs Thanks for all the valuable feedback! I’ve updated the changes accordingly—please take another look when you have time. |
What tests validate the behavior is the same both with and without the shortcut? Tnx. |
@RogerRiggs I added a test function. Please take a look. |
Validate class name length immediately after GetStringUTFLength() in Class.forName0. This prevents potential issues caused by overly long class names before they reach later code that would reject them, throwing ClassNotFoundException early.
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26802/head:pull/26802
$ git checkout pull/26802
Update a local copy of the PR:
$ git checkout pull/26802
$ git pull https://git.openjdk.org/jdk.git pull/26802/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26802
View PR using the GUI difftool:
$ git pr show -t 26802
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26802.diff
Using Webrev
Link to Webrev Comment