Skip to content

Commit

Permalink
fix: invalid subheader type would throw npe and make the extract loop
Browse files Browse the repository at this point in the history
closes #73
  • Loading branch information
gotson committed Jan 27, 2022
1 parent 306bb60 commit 7b16b3d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/github/junrar/Archive.java
Expand Up @@ -45,6 +45,7 @@
import com.github.junrar.rarfile.RARVersion;
import com.github.junrar.rarfile.SignHeader;
import com.github.junrar.rarfile.SubBlockHeader;
import com.github.junrar.rarfile.SubBlockHeaderType;
import com.github.junrar.rarfile.UnixOwnersHeader;
import com.github.junrar.rarfile.UnrarHeadertype;
import com.github.junrar.unpack.ComprDataIO;
Expand Down Expand Up @@ -449,7 +450,9 @@ private void readHeaders(final long fileLength) throws IOException, RarException
final SubBlockHeader subHead = new SubBlockHeader(blockHead,
subHeadbuffer);
subHead.print();
switch (subHead.getSubType()) {
SubBlockHeaderType subType = subHead.getSubType();
if (subType == null) break;
switch (subType) {
case MAC_HEAD: {
final byte[] macHeaderbuffer = safelyAllocate(MacInfoHeader.MacInfoHeaderSize, MAX_HEADER_SIZE);
rawData.readFully(macHeaderbuffer, macHeaderbuffer.length);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/github/junrar/AbnormalFilesTest.java
Expand Up @@ -58,7 +58,8 @@ public void extractFromStream(String filePath, Class<?> expectedException) throw
private static Stream<Arguments> provideFilesAndExpectedExceptionType() {
return Stream.of(
Arguments.of("abnormal/corrupt-header.rar", CorruptHeaderException.class),
Arguments.of("abnormal/mainHeaderNull.rar", BadRarArchiveException.class)
Arguments.of("abnormal/mainHeaderNull.rar", BadRarArchiveException.class),
Arguments.of("abnormal/loop.rar", CorruptHeaderException.class)
);
}
}
Binary file not shown.

0 comments on commit 7b16b3d

Please sign in to comment.