Rar3Decoder.cpp (p7zip_15.14.1_src_all) | : | Rar3Decoder.cpp (p7zip_16.02_src_all) | ||
---|---|---|---|---|
skipping to change at line 157 | skipping to change at line 157 | |||
_tempFilters[tempFilterIndex] = 0; | _tempFilters[tempFilterIndex] = 0; | |||
} | } | |||
HRESULT CDecoder::WriteBuf() | HRESULT CDecoder::WriteBuf() | |||
{ | { | |||
UInt32 writtenBorder = _wrPtr; | UInt32 writtenBorder = _wrPtr; | |||
UInt32 writeSize = (_winPos - writtenBorder) & kWindowMask; | UInt32 writeSize = (_winPos - writtenBorder) & kWindowMask; | |||
FOR_VECTOR (i, _tempFilters) | FOR_VECTOR (i, _tempFilters) | |||
{ | { | |||
CTempFilter *filter = _tempFilters[i]; | CTempFilter *filter = _tempFilters[i]; | |||
if (filter == NULL) | if (!filter) | |||
continue; | continue; | |||
if (filter->NextWindow) | if (filter->NextWindow) | |||
{ | { | |||
filter->NextWindow = false; | filter->NextWindow = false; | |||
continue; | continue; | |||
} | } | |||
UInt32 blockStart = filter->BlockStart; | UInt32 blockStart = filter->BlockStart; | |||
UInt32 blockSize = filter->BlockSize; | UInt32 blockSize = filter->BlockSize; | |||
if (((blockStart - writtenBorder) & kWindowMask) < writeSize) | if (((blockStart - writtenBorder) & kWindowMask) < writeSize) | |||
{ | { | |||
skipping to change at line 190 | skipping to change at line 190 | |||
{ | { | |||
UInt32 tailSize = kWindowSize - blockStart; | UInt32 tailSize = kWindowSize - blockStart; | |||
_vm.SetMemory(0, _window + blockStart, tailSize); | _vm.SetMemory(0, _window + blockStart, tailSize); | |||
_vm.SetMemory(tailSize, _window, blockEnd); | _vm.SetMemory(tailSize, _window, blockEnd); | |||
} | } | |||
NVm::CBlockRef outBlockRef; | NVm::CBlockRef outBlockRef; | |||
ExecuteFilter(i, outBlockRef); | ExecuteFilter(i, outBlockRef); | |||
while (i + 1 < _tempFilters.Size()) | while (i + 1 < _tempFilters.Size()) | |||
{ | { | |||
CTempFilter *nextFilter = _tempFilters[i + 1]; | CTempFilter *nextFilter = _tempFilters[i + 1]; | |||
if (nextFilter == NULL || nextFilter->BlockStart != blockStart || | if (!nextFilter | |||
nextFilter->BlockSize != outBlockRef.Size || nextFilter->NextWindo | || nextFilter->BlockStart != blockStart | |||
w) | || nextFilter->BlockSize != outBlockRef.Size | |||
|| nextFilter->NextWindow) | ||||
break; | break; | |||
_vm.SetMemory(0, _vm.GetDataPointer(outBlockRef.Offset), outBlockRef.S ize); | _vm.SetMemory(0, _vm.GetDataPointer(outBlockRef.Offset), outBlockRef.S ize); | |||
ExecuteFilter(++i, outBlockRef); | ExecuteFilter(++i, outBlockRef); | |||
} | } | |||
WriteDataToStream(_vm.GetDataPointer(outBlockRef.Offset), outBlockRef.Si ze); | WriteDataToStream(_vm.GetDataPointer(outBlockRef.Offset), outBlockRef.Si ze); | |||
_writtenFileSize += outBlockRef.Size; | _writtenFileSize += outBlockRef.Size; | |||
writtenBorder = blockEnd; | writtenBorder = blockEnd; | |||
writeSize = (_winPos - writtenBorder) & kWindowMask; | writeSize = (_winPos - writtenBorder) & kWindowMask; | |||
} | } | |||
else | else | |||
{ | { | |||
for (unsigned j = i; j < _tempFilters.Size(); j++) | for (unsigned j = i; j < _tempFilters.Size(); j++) | |||
{ | { | |||
CTempFilter *filter = _tempFilters[j]; | CTempFilter *filter2 = _tempFilters[j]; | |||
if (filter != NULL && filter->NextWindow) | if (filter2 && filter2->NextWindow) | |||
filter->NextWindow = false; | filter2->NextWindow = false; | |||
} | } | |||
_wrPtr = writtenBorder; | _wrPtr = writtenBorder; | |||
return S_OK; // check it | return S_OK; // check it | |||
} | } | |||
} | } | |||
} | } | |||
_wrPtr = _winPos; | _wrPtr = _winPos; | |||
return WriteArea(writtenBorder, _winPos); | return WriteArea(writtenBorder, _winPos); | |||
} | } | |||
skipping to change at line 271 | skipping to change at line 273 | |||
return false; | return false; | |||
filter = new CFilter; | filter = new CFilter; | |||
_filters.Add(filter); | _filters.Add(filter); | |||
} | } | |||
else | else | |||
{ | { | |||
filter = _filters[filterIndex]; | filter = _filters[filterIndex]; | |||
filter->ExecCount++; | filter->ExecCount++; | |||
} | } | |||
int numEmptyItems = 0; | unsigned numEmptyItems = 0; | |||
unsigned i; | ||||
for (i = 0; i < _tempFilters.Size(); i++) | ||||
{ | { | |||
_tempFilters[i - numEmptyItems] = _tempFilters[i]; | FOR_VECTOR (i, _tempFilters) | |||
if (_tempFilters[i] == NULL) | { | |||
numEmptyItems++; | _tempFilters[i - numEmptyItems] = _tempFilters[i]; | |||
if (numEmptyItems > 0) | if (!_tempFilters[i]) | |||
_tempFilters[i] = NULL; | numEmptyItems++; | |||
if (numEmptyItems != 0) | ||||
_tempFilters[i] = NULL; | ||||
} | ||||
} | } | |||
if (numEmptyItems == 0) | if (numEmptyItems == 0) | |||
{ | { | |||
_tempFilters.Add(NULL); | _tempFilters.Add(NULL); | |||
numEmptyItems = 1; | numEmptyItems = 1; | |||
} | } | |||
CTempFilter *tempFilter = new CTempFilter; | CTempFilter *tempFilter = new CTempFilter; | |||
_tempFilters[_tempFilters.Size() - numEmptyItems] = tempFilter; | _tempFilters[_tempFilters.Size() - numEmptyItems] = tempFilter; | |||
tempFilter->FilterIndex = filterIndex; | tempFilter->FilterIndex = filterIndex; | |||
skipping to change at line 306 | skipping to change at line 309 | |||
tempFilter->BlockSize = filter->BlockSize; | tempFilter->BlockSize = filter->BlockSize; | |||
tempFilter->NextWindow = _wrPtr != _winPos && ((_wrPtr - _winPos) & kWindowMas k) <= blockStart; | tempFilter->NextWindow = _wrPtr != _winPos && ((_wrPtr - _winPos) & kWindowMas k) <= blockStart; | |||
memset(tempFilter->InitR, 0, sizeof(tempFilter->InitR)); | memset(tempFilter->InitR, 0, sizeof(tempFilter->InitR)); | |||
tempFilter->InitR[3] = NVm::kGlobalOffset; | tempFilter->InitR[3] = NVm::kGlobalOffset; | |||
tempFilter->InitR[4] = tempFilter->BlockSize; | tempFilter->InitR[4] = tempFilter->BlockSize; | |||
tempFilter->InitR[5] = filter->ExecCount; | tempFilter->InitR[5] = filter->ExecCount; | |||
if (firstByte & 0x10) | if (firstByte & 0x10) | |||
{ | { | |||
UInt32 initMask = inp.ReadBits(NVm::kNumGpRegs); | UInt32 initMask = inp.ReadBits(NVm::kNumGpRegs); | |||
for (int i = 0; i < NVm::kNumGpRegs; i++) | for (unsigned i = 0; i < NVm::kNumGpRegs; i++) | |||
if (initMask & (1 << i)) | if (initMask & (1 << i)) | |||
tempFilter->InitR[i] = inp.ReadEncodedUInt32(); | tempFilter->InitR[i] = inp.ReadEncodedUInt32(); | |||
} | } | |||
bool isOK = true; | bool isOK = true; | |||
if (newFilter) | if (newFilter) | |||
{ | { | |||
UInt32 vmCodeSize = inp.ReadEncodedUInt32(); | UInt32 vmCodeSize = inp.ReadEncodedUInt32(); | |||
if (vmCodeSize >= kVmCodeSizeMax || vmCodeSize == 0) | if (vmCodeSize >= kVmCodeSizeMax || vmCodeSize == 0) | |||
return false; | return false; | |||
for (UInt32 i = 0; i < vmCodeSize; i++) | for (UInt32 i = 0; i < vmCodeSize; i++) | |||
_vmCode[i] = (Byte)inp.ReadBits(8); | _vmCode[i] = (Byte)inp.ReadBits(8); | |||
isOK = filter->PrepareProgram(_vmCode, vmCodeSize); | isOK = filter->PrepareProgram(_vmCode, vmCodeSize); | |||
} | } | |||
Byte *globalData = &tempFilter->GlobalData[0]; | { | |||
for (i = 0; i < NVm::kNumGpRegs; i++) | Byte *globalData = &tempFilter->GlobalData[0]; | |||
NVm::SetValue32(&globalData[i * 4], tempFilter->InitR[i]); | for (unsigned i = 0; i < NVm::kNumGpRegs; i++) | |||
NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockSize], tempFilter->Block | NVm::SetValue32(&globalData[i * 4], tempFilter->InitR[i]); | |||
Size); | NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockSize], tempFilter->Blo | |||
NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockPos], 0); // It was comm | ckSize); | |||
ented. why? | NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockPos], 0); // It was co | |||
NVm::SetValue32(&globalData[NVm::NGlobalOffset::kExecCount], filter->ExecCount | mmented. why? | |||
); | NVm::SetValue32(&globalData[NVm::NGlobalOffset::kExecCount], filter->ExecCou | |||
nt); | ||||
} | ||||
if (firstByte & 8) | if (firstByte & 8) | |||
{ | { | |||
UInt32 dataSize = inp.ReadEncodedUInt32(); | UInt32 dataSize = inp.ReadEncodedUInt32(); | |||
if (dataSize > NVm::kGlobalSize - NVm::kFixedGlobalSize) | if (dataSize > NVm::kGlobalSize - NVm::kFixedGlobalSize) | |||
return false; | return false; | |||
CRecordVector<Byte> &globalData = tempFilter->GlobalData; | CRecordVector<Byte> &globalData = tempFilter->GlobalData; | |||
unsigned requiredSize = (unsigned)(dataSize + NVm::kFixedGlobalSize); | unsigned requiredSize = (unsigned)(dataSize + NVm::kFixedGlobalSize); | |||
if (globalData.Size() < requiredSize) | if (globalData.Size() < requiredSize) | |||
globalData.ChangeSize_KeepData(requiredSize); | globalData.ChangeSize_KeepData(requiredSize); | |||
skipping to change at line 498 | skipping to change at line 503 | |||
continue; | continue; | |||
} | } | |||
if (nextCh == 4 || nextCh == 5) | if (nextCh == 4 || nextCh == 5) | |||
{ | { | |||
UInt32 distance = 0; | UInt32 distance = 0; | |||
UInt32 length = 4; | UInt32 length = 4; | |||
if (nextCh == 4) | if (nextCh == 4) | |||
{ | { | |||
for (int i = 0; i < 3; i++) | for (int i = 0; i < 3; i++) | |||
{ | { | |||
int c = DecodePpmSymbol(); | int c2 = DecodePpmSymbol(); | |||
if (c < 0) | if (c2 < 0) | |||
{ | { | |||
PpmError = true; | PpmError = true; | |||
return S_FALSE; | return S_FALSE; | |||
} | } | |||
distance = (distance << 8) + (Byte)c; | distance = (distance << 8) + (Byte)c2; | |||
} | } | |||
distance++; | distance++; | |||
length += 28; | length += 28; | |||
} | } | |||
int c = DecodePpmSymbol(); | int c2 = DecodePpmSymbol(); | |||
if (c < 0) | if (c2 < 0) | |||
{ | { | |||
PpmError = true; | PpmError = true; | |||
return S_FALSE; | return S_FALSE; | |||
} | } | |||
length += c; | length += c2; | |||
if (distance >= _lzSize) | if (distance >= _lzSize) | |||
return S_FALSE; | return S_FALSE; | |||
CopyBlock(distance, length); | CopyBlock(distance, length); | |||
num -= (Int32)length; | num -= (Int32)length; | |||
continue; | continue; | |||
} | } | |||
} | } | |||
PutByte((Byte)c); | PutByte((Byte)c); | |||
num--; | num--; | |||
} | } | |||
skipping to change at line 734 | skipping to change at line 739 | |||
{ | { | |||
distance = rep3; | distance = rep3; | |||
rep3 = rep2; | rep3 = rep2; | |||
} | } | |||
rep2 = rep1; | rep2 = rep1; | |||
} | } | |||
rep1 = rep0; | rep1 = rep0; | |||
rep0 = distance; | rep0 = distance; | |||
} | } | |||
UInt32 sym = m_LenDecoder.Decode(&m_InBitStream.BitDecoder); | const UInt32 sym2 = m_LenDecoder.Decode(&m_InBitStream.BitDecoder); | |||
if (sym >= kLenTableSize) | if (sym2 >= kLenTableSize) | |||
return S_FALSE; | return S_FALSE; | |||
length = 2 + kLenStart[sym] + m_InBitStream.BitDecoder.ReadBits(kLenDirect Bits[sym]); | length = 2 + kLenStart[sym2] + m_InBitStream.BitDecoder.ReadBits(kLenDirec tBits[sym2]); | |||
} | } | |||
else | else | |||
{ | { | |||
rep3 = rep2; | rep3 = rep2; | |||
rep2 = rep1; | rep2 = rep1; | |||
rep1 = rep0; | rep1 = rep0; | |||
if (sym < 271) | if (sym < 271) | |||
{ | { | |||
sym -= 263; | sym -= 263; | |||
rep0 = kLen2DistStarts[sym] + m_InBitStream.BitDecoder.ReadBits(kLen2Dis tDirectBits[sym]); | rep0 = kLen2DistStarts[sym] + m_InBitStream.BitDecoder.ReadBits(kLen2Dis tDirectBits[sym]); | |||
length = 2; | length = 2; | |||
} | } | |||
else if (sym < 299) | else if (sym < 299) | |||
{ | { | |||
sym -= 271; | sym -= 271; | |||
length = kNormalMatchMinLen + (UInt32)kLenStart[sym] + m_InBitStream.Bit Decoder.ReadBits(kLenDirectBits[sym]); | length = kNormalMatchMinLen + (UInt32)kLenStart[sym] + m_InBitStream.Bit Decoder.ReadBits(kLenDirectBits[sym]); | |||
UInt32 sym = m_DistDecoder.Decode(&m_InBitStream.BitDecoder); | const UInt32 sym2 = m_DistDecoder.Decode(&m_InBitStream.BitDecoder); | |||
if (sym >= kDistTableSize) | if (sym2 >= kDistTableSize) | |||
return S_FALSE; | return S_FALSE; | |||
rep0 = kDistStart[sym]; | rep0 = kDistStart[sym2]; | |||
int numBits = kDistDirectBits[sym]; | int numBits = kDistDirectBits[sym2]; | |||
if (sym >= (kNumAlignBits * 2) + 2) | if (sym2 >= (kNumAlignBits * 2) + 2) | |||
{ | { | |||
if (numBits > kNumAlignBits) | if (numBits > kNumAlignBits) | |||
rep0 += (m_InBitStream.BitDecoder.ReadBits(numBits - kNumAlignBits) << kNumAlignBits); | rep0 += (m_InBitStream.BitDecoder.ReadBits(numBits - kNumAlignBits) << kNumAlignBits); | |||
if (PrevAlignCount > 0) | if (PrevAlignCount > 0) | |||
{ | { | |||
PrevAlignCount--; | PrevAlignCount--; | |||
rep0 += PrevAlignBits; | rep0 += PrevAlignBits; | |||
} | } | |||
else | else | |||
{ | { | |||
UInt32 sym = m_AlignDecoder.Decode(&m_InBitStream.BitDecoder); | const UInt32 sym3 = m_AlignDecoder.Decode(&m_InBitStream.BitDecoder) | |||
if (sym < (1 << kNumAlignBits)) | ; | |||
if (sym3 < (1 << kNumAlignBits)) | ||||
{ | { | |||
rep0 += sym; | rep0 += sym3; | |||
PrevAlignBits = sym; | PrevAlignBits = sym3; | |||
} | } | |||
else if (sym == (1 << kNumAlignBits)) | else if (sym3 == (1 << kNumAlignBits)) | |||
{ | { | |||
PrevAlignCount = kNumAlignReps; | PrevAlignCount = kNumAlignReps; | |||
rep0 += PrevAlignBits; | rep0 += PrevAlignBits; | |||
} | } | |||
else | else | |||
return S_FALSE; | return S_FALSE; | |||
} | } | |||
} | } | |||
else | else | |||
rep0 += m_InBitStream.BitDecoder.ReadBits(numBits); | rep0 += m_InBitStream.BitDecoder.ReadBits(numBits); | |||
skipping to change at line 868 | skipping to change at line 873 | |||
return E_NOTIMPL; | return E_NOTIMPL; | |||
return S_OK; | return S_OK; | |||
} | } | |||
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream, | STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream, | |||
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress ) | const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress ) | |||
{ | { | |||
try | try | |||
{ | { | |||
if (inSize == NULL || outSize == NULL) | if (!inSize) | |||
return E_INVALIDARG; | return E_INVALIDARG; | |||
if (_vmData == 0) | if (!_vmData) | |||
{ | { | |||
_vmData = (Byte *)::MidAlloc(kVmDataSizeMax + kVmCodeSizeMax); | _vmData = (Byte *)::MidAlloc(kVmDataSizeMax + kVmCodeSizeMax); | |||
if (_vmData == 0) | if (!_vmData) | |||
return E_OUTOFMEMORY; | return E_OUTOFMEMORY; | |||
_vmCode = _vmData + kVmDataSizeMax; | _vmCode = _vmData + kVmDataSizeMax; | |||
} | } | |||
if (_window == 0) | if (!_window) | |||
{ | { | |||
_window = (Byte *)::MidAlloc(kWindowSize); | _window = (Byte *)::MidAlloc(kWindowSize); | |||
if (_window == 0) | if (!_window) | |||
return E_OUTOFMEMORY; | return E_OUTOFMEMORY; | |||
} | } | |||
if (!m_InBitStream.BitDecoder.Create(1 << 20)) | if (!m_InBitStream.BitDecoder.Create(1 << 20)) | |||
return E_OUTOFMEMORY; | return E_OUTOFMEMORY; | |||
if (!_vm.Create()) | if (!_vm.Create()) | |||
return E_OUTOFMEMORY; | return E_OUTOFMEMORY; | |||
m_InBitStream.BitDecoder.SetStream(inStream); | m_InBitStream.BitDecoder.SetStream(inStream); | |||
m_InBitStream.BitDecoder.Init(); | m_InBitStream.BitDecoder.Init(); | |||
_outStream = outStream; | _outStream = outStream; | |||
// CCoderReleaser coderReleaser(this); | // CCoderReleaser coderReleaser(this); | |||
_unpackSize = *outSize; | _unpackSize = outSize ? *outSize : (UInt64)(Int64)-1; | |||
return CodeReal(progress); | return CodeReal(progress); | |||
} | } | |||
catch(const CInBufferException &e) { return e.ErrorCode; } | catch(const CInBufferException &e) { return e.ErrorCode; } | |||
catch(...) { return S_FALSE; } | catch(...) { return S_FALSE; } | |||
// CNewException is possible here. But probably CNewException is caused | // CNewException is possible here. But probably CNewException is caused | |||
// by error in data stream. | // by error in data stream. | |||
} | } | |||
STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size) | STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size) | |||
{ | { | |||
End of changes. 24 change blocks. | ||||
50 lines changed or deleted | 55 lines changed or added |