Skip to content

Commit

Permalink
Merge branch 'master' into fix-codepages
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock authored May 15, 2020
2 parents 4f824b1 + 632bae7 commit ce328ed
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ private byte[] ReadAndDecryptBytes(int count)
byte[] cipherText = ReadBytesNoCrc(16);
var readBytes = _rijndael.ProcessBlock(cipherText);
foreach (var readByte in readBytes)
{
_data.Enqueue(readByte);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/SharpCompress/Common/Rar/RarCryptoWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ public int ReadAndDecrypt(byte[] buffer, int offset, int count)

var readBytes = _rijndael.ProcessBlock(cipherText);
foreach (var readByte in readBytes)
{
_data.Enqueue(readByte);

}
}

for (int i = 0; i < count; i++)
{
buffer[offset + i] = _data.Dequeue();
}
}
return count;
}
Expand Down
4 changes: 4 additions & 0 deletions src/SharpCompress/Compressors/Deflate64/FastEncoderStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,19 @@ private static byte[] CreateDistanceLookup()
for (code = 0; code < 16; code++)
{
for (int n = 0; n < (1 << EXTRA_DISTANCE_BITS[code]); n++)
{
result[dist++] = (byte)code;
}
}

dist >>= 7; // from now on, all distances are divided by 128

for (; code < NUM_DIST_BASE_CODES; code++)
{
for (int n = 0; n < (1 << (EXTRA_DISTANCE_BITS[code] - 7)); n++)
{
result[256 + dist++] = (byte)code;
}
}

return result;
Expand Down
8 changes: 8 additions & 0 deletions src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,24 @@ private static byte[] GetStaticLiteralTreeLength()
{
byte[] literalTreeLength = new byte[MAX_LITERAL_TREE_ELEMENTS];
for (int i = 0; i <= 143; i++)
{
literalTreeLength[i] = 8;
}

for (int i = 144; i <= 255; i++)
{
literalTreeLength[i] = 9;
}

for (int i = 256; i <= 279; i++)
{
literalTreeLength[i] = 7;
}

for (int i = 280; i <= 287; i++)
{
literalTreeLength[i] = 8;
}

return literalTreeLength;
}
Expand Down
13 changes: 13 additions & 0 deletions src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,15 @@ private void Init(byte[] info, out int numCyclesPower, out byte[] salt, out byte

salt = new byte[saltSize];
for (int i = 0; i < saltSize; i++)
{
salt[i] = info[i + 2];
}

iv = new byte[16];
for (int i = 0; i < ivSize; i++)
{
iv[i] = info[i + saltSize + 2];
}

if (numCyclesPower > 24)
{
Expand All @@ -203,9 +207,14 @@ private byte[] InitKey(int mNumCyclesPower, byte[] salt, byte[] pass)

int pos;
for (pos = 0; pos < salt.Length; pos++)
{
key[pos] = salt[pos];
}

for (int i = 0; i < pass.Length && pos < 32; i++)
{
key[pos++] = pass[i];
}

return key;
}
Expand All @@ -225,10 +234,12 @@ private byte[] InitKey(int mNumCyclesPower, byte[] salt, byte[] pass)
// This mirrors the counter so we don't have to convert long to byte[] each round.
// (It also ensures the counter is little endian, which BitConverter does not.)
for (int i = 0; i < 8; i++)
{
if (++counter[i] != 0)
{
break;
}
}
}
return sha.GetHashAndReset();
}
Expand All @@ -246,10 +257,12 @@ private byte[] InitKey(int mNumCyclesPower, byte[] salt, byte[] pass)
// This mirrors the counter so we don't have to convert long to byte[] each round.
// (It also ensures the counter is little endian, which BitConverter does not.)
for (int i = 0; i < 8; i++)
{
if (++counter[i] != 0)
{
break;
}
}
}

sha.TransformFinalBlock(counter, 0, 0);
Expand Down
3 changes: 3 additions & 0 deletions src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ public void Unpack5(bool Solid) {
//for (uint I=DistNum;I>0;I--)
for (int I=DistNum;I>0;I--)
//OldDistN[I]=OldDistN(I-1);
{
SetOldDistN(I, OldDistN(I-1));
}

//OldDistN[0]=Distance;
SetOldDistN(0, Distance);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ public FragmentedWindow()
private void Reset()
{
for (uint I=0;I<Mem.Length;I++)
{
if (Mem[I]!=null)
{
//free(Mem[I]);
Mem[I]=null;
}
}
}


Expand Down Expand Up @@ -98,10 +100,12 @@ public byte this[size_t Item] {
}

for (uint I=1;I<MemSize.Length;I++)
{
if (Item<MemSize[I])
{
return Mem[I][Item-MemSize[I-1]];
}
}

return Mem[0][0]; // Must never happen;
}
Expand All @@ -111,10 +115,13 @@ public byte this[size_t Item] {
return;
}
for (uint I=1;I<MemSize.Length;I++)
{
if (Item<MemSize[I]) {
Mem[I][Item-MemSize[I-1]] = value;
return;
}
}
}

Mem[0][0] = value; // Must never happen;
}
}
Expand Down Expand Up @@ -151,17 +158,21 @@ public void CopyString(uint Length,uint Distance,ref size_t UnpPtr,size_t MaxWin
public void CopyData(byte[] Dest, size_t destOffset, size_t WinPos,size_t Size)
{
for (size_t I=0;I<Size;I++)
{
Dest[destOffset+I]=this[WinPos+I];
}
}


public size_t GetBlockSize(size_t StartPos,size_t RequiredSize)
{
for (uint I=0;I<MemSize.Length;I++)
{
if (StartPos<MemSize[I])
{
return Math.Min(MemSize[I]-StartPos,RequiredSize);
}
}

return 0; // Must never be here.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,24 @@ private void ShortLZ()
if (AvrLn1<37)
{
for (Length=0;;Length++)
{
if (((BitField^ShortXor1[Length]) & (~(0xff>>(int)GetShortLen1(Length))))==0)
{
break;
}
}

Inp.faddbits(GetShortLen1(Length));
}
else
{
for (Length=0;;Length++)
{
if (((BitField^ShortXor2[Length]) & (~(0xff>>(int)GetShortLen2(Length))))==0)
{
break;
}
}

Inp.faddbits(GetShortLen2(Length));
}
Expand Down Expand Up @@ -305,7 +309,10 @@ private void LongLZ()
else
{
for (Length=0;((BitField<<(int)Length)&0x8000)==0;Length++)
{
;
}

Inp.faddbits(Length+1);
}

Expand Down Expand Up @@ -557,10 +564,15 @@ private void CorrHuff(ushort[] CharSet,byte[] NumToPlace)
int I,J;
for (I=7;I>=0;I--)
for (J=0;J<32;J++)
{
CharSet[J]=(ushort)((CharSet[J] & ~0xff) | I);
}

new Span<byte>(NumToPlace, 0, NToPl.Length).Clear();
for (I=6;I>=0;I--)
{
NumToPlace[I]=(byte)((7-I)*32);
}
}

private void CopyString15(uint Distance,uint Length)
Expand All @@ -577,7 +589,10 @@ private uint DecodeNum(uint Num,uint StartPos,uint[] DecTab,uint[] PosTab)
{
int I;
for (Num&=0xfff0,I=0;DecTab[I]<=Num;I++)
{
StartPos++;
}

Inp.faddbits(StartPos);
return(((Num-(I != 0 ? DecTab[I-1]:0))>>(int)(16-StartPos))+PosTab[StartPos]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ private bool ReadTables20()
Inp.addbits(7);
}
while (N-- > 0 && I<TableSize)
{
Table[I++]=0;
}
}
}
TablesRead2=true;
Expand All @@ -319,7 +321,9 @@ private bool ReadTables20()
if (UnpAudioBlock)
{
for (uint I=0;I<UnpChannels;I++)
{
MakeDecodeTables(Table,(int)(I*MC20),MD[I],MC20);
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ private void Unpack5(bool Solid)
uint DistNum=MainSlot-258;
uint Distance=OldDist[DistNum];
for (uint I=DistNum;I>0;I--)
{
OldDist[I]=OldDist[I-1];
}

OldDist[0]=Distance;

uint LengthSlot=DecodeNumber(Inp,BlockTables.RD);
Expand Down Expand Up @@ -586,7 +589,9 @@ private byte[] ApplyFilter(byte[] __d,uint DataSize,UnpackFilter Flt)
{
byte PrevByte=0;
for (uint DestPos=CurChannel;DestPos<DataSize;DestPos+=Channels)
{
DstData[DestPos]=(PrevByte-=__d[Data+SrcPos++]);
}
}
return DstData;
}
Expand Down Expand Up @@ -742,7 +747,10 @@ private bool ReadTables(BitInput Inp,ref UnpackBlockHeader Header, ref UnpackBlo
{
ZeroCount+=2;
while (ZeroCount-- > 0 && I<BitLength.Length)
{
BitLength[I++]=0;
}

I--;
}
}
Expand Down Expand Up @@ -818,7 +826,9 @@ private bool ReadTables(BitInput Inp,ref UnpackBlockHeader Header, ref UnpackBlo
Inp.faddbits(7);
}
while (N-- > 0 && I<TableSize)
{
Table[I++]=0;
}
}
}
TablesRead5=true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ private void Init(size_t WinSize,bool Solid)
if (Grow)
{
for (size_t I=1;I<=MaxWinSize;I++)
{
NewWindow[(UnpPtr-I)&(WinSize-1)]=Window[(UnpPtr-I)&(MaxWinSize-1)];
}
}

//if (Window!=null)
Expand Down Expand Up @@ -263,7 +265,9 @@ private void MakeDecodeTables(byte[] LengthTable, int offset, DecodeTable Dec,ui
uint[] LengthCount = new uint[16];
//memset(LengthCount,0,sizeof(LengthCount));
for (size_t I=0;I<Size;I++)
{
LengthCount[LengthTable[offset+I] & 0xf]++;
}

// We must not calculate the number of zero length codes.
LengthCount[0]=0;
Expand Down Expand Up @@ -365,7 +369,9 @@ private void MakeDecodeTables(byte[] LengthTable, int offset, DecodeTable Dec,ui
// Find the upper limit for current bit field and adjust the bit length
// accordingly if necessary.
while (CurBitLength<Dec.DecodeLen.Length && BitField>=Dec.DecodeLen[CurBitLength])
{
CurBitLength++;
}

// Translation of right aligned bit string to bit length.
Dec.QuickLen[Code]=CurBitLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ private uint DecodeNumber(BitInput Inp,DecodeTable Dec)
// Detect the real bit length for current code.
uint Bits=15;
for (uint I=Dec.QuickBits+1;I<15;I++)
{
if (BitField<Dec.DecodeLen[I])
{
Bits=I;
break;
}
}

Inp.addbits(Bits);

Expand Down
5 changes: 5 additions & 0 deletions src/SharpCompress/Compressors/Xz/Crc32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private static UInt32[] InitializeTable(UInt32 polynomial)
{
var entry = (UInt32)i;
for (var j = 0; j < 8; j++)
{
if ((entry & 1) == 1)
{
entry = (entry >> 1) ^ polynomial;
Expand All @@ -45,6 +46,7 @@ private static UInt32[] InitializeTable(UInt32 polynomial)
{
entry = entry >> 1;
}
}

createTable[i] = entry;
}
Expand All @@ -61,7 +63,10 @@ private static UInt32 CalculateHash(UInt32[] table, UInt32 seed, IList<byte> buf
{
var crc = seed;
for (var i = start; i < size - start; i++)
{
crc = (crc >> 8) ^ table[buffer[i] ^ crc & 0xff];
}

return crc;
}

Expand Down
Loading

0 comments on commit ce328ed

Please sign in to comment.