RFR: 8280409: JarFile::verifiableEntry can fail with NPE accessing ze.getName()

Sean Mullan mullan at openjdk.java.net
Mon Feb 7 18:47:09 UTC 2022


On Mon, 7 Feb 2022 16:52:07 GMT, Lance Andersen <lancea at openjdk.org> wrote:

>> `JarException` is a subclass of `ZipException` though, so I think this would be ok to throw and still be compliant with the specification.
>
> Looking at this a bit more,  it looks like `JariFile::initializeVerifier` is the only place currently in `JarFile` that could throw a `JarException` and that method could be called from `JarFile::getInputStream`
> 
> As `verifiableEntry` is only called from `JarFile::getInputStream `and this change validates the `ZipEntry` for being null, which is should,  the only other possible error would be in the unlikely event. `ZipEntry` was subclassed passed into `JarFile::getInputStream` resulting in the call to `ZipEntry::getName` returning null(in which case `ZipFile::getEntry` will return a `NullPointerException`) or the name being invalid resulting once again in a possible null value for the returned `ZipEntry` from `JarFile::getJarEntry` (which calls `ZipFile::getEntry`)
> 
> 
> I am still leaning towards a `ZipException`, not a `JarException`, thrown from `verifiableEntry`.
> 
> That being said, I will go with whatever the consensus is.

If you are pretty sure the only other case are as above, I wonder if a simpler fix would be to change `verifiableEntry()` to check for these null cases and throw a `ZipException` which will get directly propagated by `getInputStream()`?

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

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


More information about the core-libs-dev mailing list