edmund-wagner / junrar

plain java unrar util (former sf project)
Other
186 stars 90 forks source link

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

Open justincranford opened 7 years ago

justincranford commented 7 years ago

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 commented 6 years ago

I opened a pull request.

https://github.com/edmund-wagner/junrar/pull/43