Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ private void UnstoreFile()

private void Unpack29(bool solid)
{
Span<int> DDecode = stackalloc int[PackDef.DC];
Span<byte> DBits = stackalloc byte[PackDef.DC];

int Bits;

if (DDecode[1] == 0)
Expand Down Expand Up @@ -1028,7 +1025,7 @@ private bool ReadVMCode()
vmCode.Add((byte)(GetBits() >> 8));
AddBits(8);
}
return (AddVMCode(FirstByte, vmCode, Length));
return AddVMCode(FirstByte, vmCode);
}

private bool ReadVMCodePPM()
Expand Down Expand Up @@ -1073,10 +1070,10 @@ private bool ReadVMCodePPM()
}
vmCode.Add((byte)Ch); // VMCode[I]=Ch;
}
return (AddVMCode(FirstByte, vmCode, Length));
return AddVMCode(FirstByte, vmCode);
}

private bool AddVMCode(int firstByte, List<byte> vmCode, int length)
private bool AddVMCode(int firstByte, List<byte> vmCode)
{
var Inp = new BitInput();
Inp.InitBitInput();
Expand Down Expand Up @@ -1199,19 +1196,28 @@ private bool AddVMCode(int firstByte, List<byte> vmCode, int length)
{
return (false);
}
Span<byte> VMCode = stackalloc byte[VMCodeSize];
for (var I = 0; I < VMCodeSize; I++)

var VMCode = ArrayPool<byte>.Shared.Rent(VMCodeSize);
try
{
if (Inp.Overflow(3))
for (var I = 0; I < VMCodeSize; I++)
{
return (false);
if (Inp.Overflow(3))
{
return (false);
}

VMCode[I] = (byte)(Inp.GetBits() >> 8);
Inp.AddBits(8);
}
VMCode[I] = (byte)(Inp.GetBits() >> 8);
Inp.AddBits(8);
}

// VM.Prepare(&VMCode[0],VMCodeSize,&Filter->Prg);
rarVM.prepare(VMCode, VMCodeSize, Filter.Program);
// VM.Prepare(&VMCode[0],VMCodeSize,&Filter->Prg);
rarVM.prepare(VMCode, VMCodeSize, Filter.Program);
}
finally
{
ArrayPool<byte>.Shared.Return(VMCode);
}
}
StackFilter.Program.AltCommands = Filter.Program.Commands; // StackFilter->Prg.AltCmd=&Filter->Prg.Cmd[0];
StackFilter.Program.CommandCount = Filter.Program.CommandCount;
Expand Down
Loading