Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Expected RarException, got NullPointerException, please apply this simple fix #41

Open
justincranford opened this issue Jul 10, 2017 · 1 comment

Comments

@justincranford
Copy link

Hello,

I created simple rar and zip files with WinRar to use for testing Junrar. They contain a simple text file. For the encrypted archives, the password is just "encrypted". See attachments,

For unencrypted.rar, I expected extraction to work. For everything else, I expected RarException. For the zip files, I get unexpected NullPointerException instead. One line of code is sufficient to reproduce the NullPointerException in Junrar.

		Archive arc = new Archive(new File("C:/encrypted.zip"));

Root cause is Junrar's Archive.java line 245. The return value of BaseBlock.getHeaderType() is null, and passing a null value to a switch() statement triggers a NullPointerException.

241 BaseBlock block = new BaseBlock(baseBlockBuffer);
242
243 block.setPositionInFile(position);
244
245 switch (block.getHeaderType()) {

To fix, please add a null check for BaseBlock.getHeaderType() and throw RarException. This simple patch should help improve the graceful error handling of Junrar.

Thank you,
Justin

encrypted.zip
unencrypted.zip

@justincranford
Copy link
Author

I opened a pull request.

#43

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant