Skip to content

Commit

Permalink
Fix bugs (Thanks Olivier)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaemendis committed May 12, 2018
1 parent 00610e6 commit 28663a4
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 78 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.github.junrar</groupId>
<artifactId>junrar</artifactId>
<packaging>jar</packaging>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.0-UBOOQUITY</version>
<name>Java UnRar</name>
<description>rar decompression library in plain java</description>
<url>https://github.com/junrar/junrar</url>
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/com/github/junrar/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@
*/
package com.github.junrar;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.github.junrar.exception.RarException;
import com.github.junrar.exception.RarException.RarExceptionType;
import com.github.junrar.impl.FileVolumeManager;
Expand All @@ -52,6 +40,18 @@
import com.github.junrar.unpack.ComprDataIO;
import com.github.junrar.unpack.Unpack;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
* The Main Rar Class; represents a rar Archive
Expand Down Expand Up @@ -387,6 +387,9 @@ private void readHeaders(long fileLength) throws IOException, RarException {
macHeader.print();
headers.add(macHeader);

newpos = blockHead.getPositionInFile() + blockHead.getDataSize() + blockHead.getHeaderSize();
rof.setPosition(newpos);

break;
}
// TODO implement other subheaders
Expand Down
139 changes: 74 additions & 65 deletions src/main/java/com/github/junrar/unpack/Unpack20.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@
*
* Source: $HeadURL$
* Last changed: $LastChangedDate$
*
* the unrar licence applies to all junrar source and binary distributions
*
* the unrar licence applies to all junrar source and binary distributions
* you are not allowed to use this source to re-create the RAR compression algorithm
*
*
* Here some html entities which can be used for escaping javadoc tags:
* "&": "&#038;" or "&amp;"
* "<": "&#060;" or "&lt;"
* ">": "&#062;" or "&gt;"
* "@": "&#064;"
* "@": "&#064;"
*/
package com.github.junrar.unpack;

import java.io.IOException;
import java.util.Arrays;

import com.github.junrar.exception.RarException;
import com.github.junrar.unpack.decode.AudioVariables;
import com.github.junrar.unpack.decode.BitDecode;
Expand All @@ -31,11 +28,14 @@
import com.github.junrar.unpack.decode.MultDecode;
import com.github.junrar.unpack.decode.RepDecode;

import java.io.IOException;
import java.util.Arrays;



/**
* DOCUMENT ME
*
*
* @author $LastChangedBy$
* @version $LastChangedRevision$
*/
Expand Down Expand Up @@ -114,7 +114,11 @@ protected void unpack20(boolean solid) throws IOException, RarException
return;
}
if (UnpAudioBlock != 0) {
int AudioNumber = decodeNumber(MD[UnpCurChannel]);
MultDecode md = MD[UnpCurChannel];
if (md == null) {
continue;
}
int AudioNumber = decodeNumber(md);

if (AudioNumber == 256) {
if (!ReadTables20())
Expand Down Expand Up @@ -208,7 +212,8 @@ protected void CopyString20(int Length, int Distance)

int DestPtr = unpPtr - Distance;
if (DestPtr < Compress.MAXWINSIZE - 300
&& unpPtr < Compress.MAXWINSIZE - 300) {
&& unpPtr < Compress.MAXWINSIZE - 300
&& DestPtr >= 0) {
window[unpPtr++] = window[DestPtr++];
window[unpPtr++] = window[DestPtr++];
while (Length > 2) {
Expand All @@ -224,7 +229,7 @@ protected void CopyString20(int Length, int Distance)
}

protected void makeDecodeTables(byte[] lenTab, int offset, Decode dec,
int size)
int size)
{
int[] lenCount = new int[16];
int[] tmpPos = new int[16];
Expand Down Expand Up @@ -321,8 +326,8 @@ protected int decodeNumber(Decode dec)
// N = 0;
// }
// return (dec.getDecodeNum()[N]);
int[] decodeLen = dec.getDecodeLen();
if (bitField < decodeLen[8]) {
int[] decodeLen = dec.getDecodeLen();
if (bitField < decodeLen[8]) {
if (bitField < decodeLen[4]) {
if (bitField < decodeLen[2]) {
if (bitField < decodeLen[1]) {
Expand Down Expand Up @@ -451,8 +456,12 @@ protected boolean ReadTables20() throws IOException, RarException
return (true);
}
if (UnpAudioBlock != 0)
for (I = 0; I < UnpChannels; I++)
makeDecodeTables(Table, I * Compress.MC20, MD[I], Compress.MC20);
for (I = 0; I < UnpChannels; I++) {
MultDecode md = MD[I];
if (md != null) {
makeDecodeTables(Table, I * Compress.MC20, md, Compress.MC20);
}
}
else {
makeDecodeTables(Table, 0, LD, Compress.NC20);
makeDecodeTables(Table, Compress.NC20, DD, Compress.DC20);
Expand Down Expand Up @@ -539,56 +548,56 @@ protected byte DecodeAudio(int Delta)
v.getDif()[I] = 0;
}
switch (NumMinDif) {
case 1:
if (v.getK1() >= -16) {
v.setK1(v.getK1() - 1);// V->K1--;
}
break;
case 2:
if (v.getK1() < 16) {
v.setK1(v.getK1() + 1);// V->K1++;
}
break;
case 3:
if (v.getK2() >= -16) {
v.setK2(v.getK2() - 1);// V->K2--;
}
break;
case 4:
if (v.getK2() < 16) {
v.setK2(v.getK2() + 1);// V->K2++;
}
break;
case 5:
if (v.getK3() >= -16) {
v.setK3(v.getK3() - 1);
}
break;
case 6:
if (v.getK3() < 16) {
v.setK3(v.getK3() + 1);
}
break;
case 7:
if (v.getK4() >= -16) {
v.setK4(v.getK4() - 1);
}
break;
case 8:
if (v.getK4() < 16) {
v.setK4(v.getK4() + 1);
}
break;
case 9:
if (v.getK5() >= -16) {
v.setK5(v.getK5() - 1);
}
break;
case 10:
if (v.getK5() < 16) {
v.setK5(v.getK5() + 1);
}
break;
case 1:
if (v.getK1() >= -16) {
v.setK1(v.getK1() - 1);// V->K1--;
}
break;
case 2:
if (v.getK1() < 16) {
v.setK1(v.getK1() + 1);// V->K1++;
}
break;
case 3:
if (v.getK2() >= -16) {
v.setK2(v.getK2() - 1);// V->K2--;
}
break;
case 4:
if (v.getK2() < 16) {
v.setK2(v.getK2() + 1);// V->K2++;
}
break;
case 5:
if (v.getK3() >= -16) {
v.setK3(v.getK3() - 1);
}
break;
case 6:
if (v.getK3() < 16) {
v.setK3(v.getK3() + 1);
}
break;
case 7:
if (v.getK4() >= -16) {
v.setK4(v.getK4() - 1);
}
break;
case 8:
if (v.getK4() < 16) {
v.setK4(v.getK4() + 1);
}
break;
case 9:
if (v.getK5() >= -16) {
v.setK5(v.getK5() - 1);
}
break;
case 10:
if (v.getK5() < 16) {
v.setK5(v.getK5() + 1);
}
break;
}
}
return ((byte) Ch);
Expand Down

0 comments on commit 28663a4

Please sign in to comment.