Update to 7-Zip Version 18.06

This commit is contained in:
Tino Reichardt
2018-12-30 12:50:20 +01:00
parent 093cf20bad
commit a488536124
116 changed files with 1830 additions and 955 deletions

View File

@@ -446,6 +446,14 @@ void CCoder::SetOutStreamSizeResume(const UInt64 *outSize)
STDMETHODIMP CCoder::SetOutStreamSize(const UInt64 *outSize)
{
/*
18.06:
We want to support GetInputProcessedSize() before CCoder::Read()
So we call m_InBitStream.Init() even before buffer allocations
m_InBitStream.Init() just sets variables to default values
But later we will call m_InBitStream.Init() again with real buffer pointers
*/
m_InBitStream.Init();
_needInitInStream = true;
SetOutStreamSizeResume(outSize);
return S_OK;

View File

@@ -517,9 +517,9 @@ HRESULT CDecoder::CodeReal(const Byte *in, size_t inSize, Byte *_win, size_t out
if (len > outSize - _pos)
return S_FALSE;
if (dist > _pos)
return S_FALSE;
size_t span = (size_t)1 << power;
if ((UInt64)dist + span > _pos)
return S_FALSE;
Byte *dest = _win + _pos - span;
const Byte *src = dest - dist;
_pos += len;

View File

@@ -148,7 +148,8 @@ void CDecoder::ExecuteFilter(unsigned tempFilterIndex, NVm::CBlockRef &outBlockR
if (!_vm.Execute(filter, tempFilter, outBlockRef, filter->GlobalData))
_unsupportedFilter = true;
delete tempFilter;
_tempFilters[tempFilterIndex] = 0;
_tempFilters[tempFilterIndex] = NULL;
_numEmptyTempFilters++;
}
HRESULT CDecoder::WriteBuf()
@@ -225,6 +226,7 @@ HRESULT CDecoder::WriteBuf()
void CDecoder::InitFilters()
{
_lastFilter = 0;
_numEmptyTempFilters = 0;
unsigned i;
for (i = 0; i < _tempFilters.Size(); i++)
delete _tempFilters[i];
@@ -274,24 +276,27 @@ bool CDecoder::AddVmCode(UInt32 firstByte, UInt32 codeSize)
filter->ExecCount++;
}
unsigned numEmptyItems = 0;
if (_numEmptyTempFilters != 0)
{
FOR_VECTOR (i, _tempFilters)
unsigned num = _tempFilters.Size();
CTempFilter **tempFilters = &_tempFilters.Front();
unsigned w = 0;
for (unsigned i = 0; i < num; i++)
{
_tempFilters[i - numEmptyItems] = _tempFilters[i];
if (!_tempFilters[i])
numEmptyItems++;
if (numEmptyItems != 0)
_tempFilters[i] = NULL;
CTempFilter *tf = tempFilters[i];
if (tf)
tempFilters[w++] = tf;
}
_tempFilters.DeleteFrom(w);
_numEmptyTempFilters = 0;
}
if (numEmptyItems == 0)
{
_tempFilters.Add(NULL);
numEmptyItems = 1;
}
if (_tempFilters.Size() > MAX_UNPACK_FILTERS)
return false;
CTempFilter *tempFilter = new CTempFilter;
_tempFilters[_tempFilters.Size() - numEmptyItems] = tempFilter;
_tempFilters.Add(tempFilter);
tempFilter->FilterIndex = filterIndex;
UInt32 blockStart = inp.ReadEncodedUInt32();

View File

@@ -189,6 +189,7 @@ class CDecoder:
NVm::CVm _vm;
CRecordVector<CFilter *> _filters;
CRecordVector<CTempFilter *> _tempFilters;
unsigned _numEmptyTempFilters;
UInt32 _lastFilter;
bool _isSolid;

View File

@@ -33,10 +33,11 @@ struct CBitStream
bs.Value = (bs.Value << 16) | GetUi16(in); \
in += 2; bs.BitPos += 16; }
const unsigned kNumHuffBits = 15;
const unsigned kNumLenSlots = 16;
const unsigned kNumPosSlots = 16;
const unsigned kNumSyms = 256 + kNumPosSlots * kNumLenSlots;
static const unsigned kNumHuffBits = 15;
static const unsigned kNumLenBits = 4;
static const unsigned kLenMask = (1 << kNumLenBits) - 1;
static const unsigned kNumPosSlots = 16;
static const unsigned kNumSyms = 256 + (kNumPosSlots << kNumLenBits);
HRESULT Decode(const Byte *in, size_t inSize, Byte *out, size_t outSize)
{
@@ -83,10 +84,10 @@ HRESULT Decode(const Byte *in, size_t inSize, Byte *out, size_t outSize)
else
{
sym -= 256;
UInt32 dist = sym / kNumLenSlots;
UInt32 len = sym & (kNumLenSlots - 1);
UInt32 dist = sym >> kNumLenBits;
UInt32 len = sym & kLenMask;
if (len == kNumLenSlots - 1)
if (len == kLenMask)
{
if (in > lim)
return S_FALSE;
@@ -99,7 +100,7 @@ HRESULT Decode(const Byte *in, size_t inSize, Byte *out, size_t outSize)
in += 2;
}
else
len += kNumLenSlots - 1;
len += kLenMask;
}
bs.BitPos -= dist;
@@ -108,7 +109,7 @@ HRESULT Decode(const Byte *in, size_t inSize, Byte *out, size_t outSize)
BIT_STREAM_NORMALIZE
if (len > outSize - pos)
if (len + 3 > outSize - pos)
return S_FALSE;
if (dist > pos)
return S_FALSE;