Skip to content
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

8279800: isAssignableFrom checks in AlgorithmParametersSpi.engineGetParameterSpec appear to be backwards #7037

Closed
wants to merge 2 commits into from

Conversation

wangweij
Copy link
Contributor

@wangweij wangweij commented Jan 11, 2022

Change the order so parent class is at the left.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8279800: isAssignableFrom checks in AlgorithmParametersSpi.engineGetParameterSpec appear to be backwards

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7037/head:pull/7037
$ git checkout pull/7037

Update a local copy of the PR:
$ git checkout pull/7037
$ git pull https://git.openjdk.java.net/jdk pull/7037/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 7037

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7037.diff

…arameterSpec appear to be backwards

8279800: isAssignableFrom checks in AlgorithmParametersSpi.engineGetParameterSpec appear to be backwards
@bridgekeeper
Copy link

bridgekeeper bot commented Jan 11, 2022

👋 Welcome back weijun! 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 openjdk bot added the rfr Pull request is ready for review label Jan 11, 2022
@openjdk
Copy link

openjdk bot commented Jan 11, 2022

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

  • security

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 security security-dev@openjdk.org label Jan 11, 2022
@mlbridge
Copy link

mlbridge bot commented Jan 11, 2022

Webrevs

Copy link
Member

@XueleiFan XueleiFan left a comment

Choose a reason for hiding this comment

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

Hm, an interesting catch. I have a concern, although.

if (IvParameterSpec.class.isAssignableFrom(paramSpec)) {
if (paramSpec.isAssignableFrom(IvParameterSpec.class)) {
Copy link
Member

Choose a reason for hiding this comment

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

The call to cast() is confusing. But if the paramSpec is AlgorithmParameterSpec.class or Object.class, what's the expected behavior? There are potential casting exception, I guess. Maybe, a exactly class matching could be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If so, then the if block will be true and the spec object is casted to your specified class (AlgorithmParameterSpec.class or Object.class) and it always succeeds.

This is exactly what I want to achieve. In fact, this bug and the other getInstance(oid) bug have the same root. I was trying to decode an algorithm identifier from its encoding. First, the encoding of the algorithm is in OID so AlgorithmParameters.getInstance() must support OID. Second, I want to get the spec from the parameters without knowing the algorithm name and the child AlgorithmParametersSpec class type, so AlgorithmParameters::getParameterSpec must support AlgorithmParameterSpec.class as the argument.

Otherwise, the program needs to know name and parameter spec type on all supported algorithms.

Choose a reason for hiding this comment

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

Interesting... In hindsight, the cast call sort of confirms that the intended ordering is the suggested one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check ensures casting always succeeds. The fact that this has not been noticed for such a long time means everyone is using the exact subclass type when calling the method.

Choose a reason for hiding this comment

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

Right, I suppose so.

Choose a reason for hiding this comment

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

PBEKeyFactory.java, PBKDF2Core.java and PBKDF2HmacSHA1Factory.java also have isAssignableFrom() calls which seem backward. Perhaps covering them as well?

Copy link
Member

Choose a reason for hiding this comment

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

If so, then the if block will be true and the spec object is casted to your specified class (AlgorithmParameterSpec.class or Object.class) and it always succeeds.

This is exactly what I want to achieve.

Unfortunately, there is a returned value that we cannot return an object of any class.

Copy link
Member

Choose a reason for hiding this comment

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

If so, then the if block will be true and the spec object is casted to your specified class (AlgorithmParameterSpec.class or Object.class) and it always succeeds.
This is exactly what I want to achieve.

Unfortunately, there is a returned value that we cannot return an object of any class.

Oh, I missed that the paramSpec should be of class T, which extends AlgorithmParameterSpec. Then, I have no more concerns.


static void test(String algorithm, AlgorithmParameterSpec spec,
Class<? extends AlgorithmParameterSpec>... classes) throws Exception {
var ap1 = AlgorithmParameters.getInstance(algorithm);

Choose a reason for hiding this comment

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

nit: Print out the algorithm which has been tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can, but if an exception is thrown, I can find out which algorithm has a problem by looking at the line number.

Choose a reason for hiding this comment

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

Yes, just thought that reporting the algorithm to the test output seems more informative. Otherwise, always have to dig out the source to find out what has been covered.

@wangweij
Copy link
Contributor Author

New commit pushed. Turns out PBKDF2HmacSHA1Factory.java is useless now. The algorithm is now implemented as a sub-class of PBKDF2Core.

@openjdk
Copy link

openjdk bot commented Jan 12, 2022

@wangweij 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:

8279800: isAssignableFrom checks in AlgorithmParametersSpi.engineGetParameterSpec appear to be backwards

Reviewed-by: xuelei, valeriep

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 101 new commits pushed to the master branch:

  • d70545d: 8258603: c1 IR::verify is expensive
  • 0a094d7: 8268081: Upgrade Unicode Data Files to 14.0.0
  • ddddec7: 8274243: Implement fast-path for ASCII-compatible CharsetEncoders on aarch64
  • 8fed8ab: 8278065: Refactor subclassAudits to use ClassValue
  • f54ce84: 8238161: use os::fopen in HS code where possible
  • ff0cb98: 8279536: jdk/nio/zipfs/ZipFSOutputStreamTest.java timed out
  • ece98d8: 8278461: Use Executable.getSharedParameterTypes() instead of Executable.getParameterTypes() in trusted code
  • 525b20f: 8279676: Dubious YMM register clearing in x86_64 arraycopy stubs
  • 4f0b650: 8278581: Improve reference processing statistics log output
  • bd339aa: 8277627: Fix copyright years in some jvmci files
  • ... and 91 more: https://git.openjdk.java.net/jdk/compare/8dc4437d002db5d025b47f48e7420e3bae55bdec...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 ready Pull request is ready to be integrated label Jan 12, 2022
Copy link

@valeriepeng valeriepeng left a comment

Choose a reason for hiding this comment

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

Changes look good. Thanks~

@wangweij
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jan 13, 2022

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

  • 1228b2f: 8261455: Automatically generate the CDS archive if necessary
  • d70545d: 8258603: c1 IR::verify is expensive
  • 0a094d7: 8268081: Upgrade Unicode Data Files to 14.0.0
  • ddddec7: 8274243: Implement fast-path for ASCII-compatible CharsetEncoders on aarch64
  • 8fed8ab: 8278065: Refactor subclassAudits to use ClassValue
  • f54ce84: 8238161: use os::fopen in HS code where possible
  • ff0cb98: 8279536: jdk/nio/zipfs/ZipFSOutputStreamTest.java timed out
  • ece98d8: 8278461: Use Executable.getSharedParameterTypes() instead of Executable.getParameterTypes() in trusted code
  • 525b20f: 8279676: Dubious YMM register clearing in x86_64 arraycopy stubs
  • 4f0b650: 8278581: Improve reference processing statistics log output
  • ... and 92 more: https://git.openjdk.java.net/jdk/compare/8dc4437d002db5d025b47f48e7420e3bae55bdec...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 13, 2022

@wangweij Pushed as commit cb25029.

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

@wangweij wangweij deleted the 8279800 branch January 14, 2022 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated security security-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

3 participants