-
Notifications
You must be signed in to change notification settings - Fork 20
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
Fix: Fix possible Null Pointer Exception #406
Conversation
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
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.
I think the verification should be performed by the downstream library, and adding 0 check here is wrong
The PR title says NullPointerException while the fix checks for empty array. It does not sound aligned |
@vlsi, I believe there is a sufficient description to describe the issue. The title is aligned with the problem. |
@loosebazooka , we should not add arbitrary checks. Is there anything in ASN1Sequence.getInstance that says “empty byte array must not be passed there”? Then, I do not like to merge changes without corresponding tests. |
I mean I agree here, this is a bouncy castle issue, but it still causes crashes in our code. |
If it is a bouncy castle issue, it should be fixed and tested at bouncy castle side, so everybody wins from the improvement.
oss-fuzz is non-deterministic, so it is not guaranteed to catch it. The cases identified by oss-fuzz should be baked into reproducible tests to prevent regressions. |
@loosebazooka Indeed, this could be reproducible. |
@arthurscchan can you elaborate or point to the docs on how reproducing works for ossfuzz, it might also make sense to just bake these test cases into our testsuite anyway. |
In general, the oss-fuzz tool provides function to reproduce testcase, see https://google.github.io/oss-fuzz/advanced-topics/reproducing/#reproducing-bugs |
In addition to this, we also added some documentation here: https://github.com/sigstore/sigstore-java/blob/main/DEVELOPMENT.md#reproduce-oss-fuzz-crash To reproduce this crash:
|
I think it still makes sense to include a testcase in KeysTest.java to document this behavior. The relationship between ossfuzz and this project is not guaranteed to be transferable. Anyone forking this project or keeping a private copy should be allowed the benefit of a full testsuite. |
@arthurscchan can you do this? |
I can do it too, if arthur is busy |
Yes, I will create a unit test case for this issue and push to this PR. I am assuming the unit test case should be add in here (https://github.com/sigstore/sigstore-java/blob/main/sigstore-java/src/test/java/dev/sigstore/encryption/KeysTest.java), right? |
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
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.
Please structure tests in such a way that they fail before you apply the fix.
The current test passes even with the current sigstore-java
, so it does not look like the test is helpful
sigstore-java/src/test/java/dev/sigstore/encryption/KeysTest.java
Outdated
Show resolved
Hide resolved
sigstore-java/src/test/java/dev/sigstore/encryption/KeysTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
sigstore-java/src/test/java/dev/sigstore/encryption/KeysTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
The bug has nothing to do with sigstore-java, and the bug belongs to bc-java. If we commit a workaround, there should be a reference to bc-java issue, so we could drop the workaround once bc-java issue is resolved |
Sure, we can link to bcgit/bc-java#1370 for now. |
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
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.
thanks
Summary
In PublicKeyFactory Line 108, SubjectPublicKeyInfo.getInstance method could return null and make PublicKeyFactory Line 148 throws a NullPointerException.
From InputStream javadoc, we see that if the end of the stream is reached, it will return -1. Which means that if an empty byte array is provided, the tag will be -1 and it will return null in ASN1InputStream. In this case, it will trigger the null pointer exception above. Thus this fix adds an additional checking to ensure the PEM content is not an empty array.
Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=57247
Release Note
Documentation