mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 09:15:00 -06:00
16.01
This commit is contained in:
committed by
Kornel Lesiński
parent
66ac98bb02
commit
bec3b479dc
@@ -404,11 +404,11 @@ HRESULT CDecoder::Decode(
|
||||
len = password.Len();
|
||||
}
|
||||
CByteBuffer buffer(len * 2);
|
||||
for (size_t i = 0; i < len; i++)
|
||||
for (size_t k = 0; k < len; k++)
|
||||
{
|
||||
wchar_t c = passwordBSTR[i];
|
||||
((Byte *)buffer)[i * 2] = (Byte)c;
|
||||
((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
|
||||
wchar_t c = passwordBSTR[k];
|
||||
((Byte *)buffer)[k * 2] = (Byte)c;
|
||||
((Byte *)buffer)[k * 2 + 1] = (Byte)(c >> 8);
|
||||
}
|
||||
RINOK(cryptoSetPassword->CryptoSetPassword((const Byte *)buffer, (UInt32)buffer.Size()));
|
||||
}
|
||||
|
||||
@@ -148,9 +148,9 @@ HRESULT CEncoder::CreateMixerCoder(
|
||||
|
||||
RINOK(_mixer->SetBindInfo(_bindInfo));
|
||||
|
||||
FOR_VECTOR (i, _options.Methods)
|
||||
FOR_VECTOR (m, _options.Methods)
|
||||
{
|
||||
const CMethodFull &methodFull = _options.Methods[i];
|
||||
const CMethodFull &methodFull = _options.Methods[m];
|
||||
|
||||
CCreatedCoder cod;
|
||||
|
||||
@@ -410,9 +410,9 @@ HRESULT CEncoder::Encode(
|
||||
mtOutStreamNotifySpec->_stream = outStream;
|
||||
mtOutStreamNotifySpec->_mtProgresSpec = mtProgressSpec;
|
||||
|
||||
FOR_VECTOR(i, tempBufferSpecs)
|
||||
FOR_VECTOR(t, tempBufferSpecs)
|
||||
{
|
||||
tempBufferSpecs[i]->_mtProgresSpec = mtProgressSpec;
|
||||
tempBufferSpecs[t]->_mtProgresSpec = mtProgressSpec;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,9 +591,9 @@ HRESULT CEncoder::EncoderConstr()
|
||||
continue;
|
||||
}
|
||||
|
||||
int i = _bindInfo.FindStream_in_PackStreams(outIndex);
|
||||
if (i >= 0)
|
||||
_bindInfo.PackStreams.MoveToFront(i);
|
||||
int si = _bindInfo.FindStream_in_PackStreams(outIndex);
|
||||
if (si >= 0)
|
||||
_bindInfo.PackStreams.MoveToFront(si);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,13 +319,15 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
curUnpacked += _db.Files[k].Size;
|
||||
}
|
||||
|
||||
HRESULT result = folderOutStream->Init(fileIndex,
|
||||
allFilesMode ? NULL : indices + i,
|
||||
numSolidFiles);
|
||||
{
|
||||
HRESULT result = folderOutStream->Init(fileIndex,
|
||||
allFilesMode ? NULL : indices + i,
|
||||
numSolidFiles);
|
||||
|
||||
i += numSolidFiles;
|
||||
i += numSolidFiles;
|
||||
|
||||
RINOK(result);
|
||||
RINOK(result);
|
||||
}
|
||||
|
||||
// to test solid block with zero unpacked size we disable that code
|
||||
if (folderOutStream->WasWritingFinished())
|
||||
|
||||
@@ -429,11 +429,11 @@ HRESULT CHandler::SetMethodToProp(CNum folderIndex, PROPVARIANT *prop) const
|
||||
name = "LZMA2";
|
||||
if (propsSize == 1)
|
||||
{
|
||||
Byte p = props[0];
|
||||
if ((p & 1) == 0)
|
||||
ConvertUInt32ToString((UInt32)((p >> 1) + 12), s);
|
||||
Byte d = props[0];
|
||||
if ((d & 1) == 0)
|
||||
ConvertUInt32ToString((UInt32)((d >> 1) + 12), s);
|
||||
else
|
||||
GetStringForSizeValue(s, 3 << ((p >> 1) + 11));
|
||||
GetStringForSizeValue(s, 3 << ((d >> 1) + 11));
|
||||
}
|
||||
}
|
||||
else if (id == k_PPMD)
|
||||
|
||||
@@ -675,14 +675,16 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
|
||||
static HRESULT ParseBond(UString &srcString, UInt32 &coder, UInt32 &stream)
|
||||
{
|
||||
stream = 0;
|
||||
int index = ParseStringToUInt32(srcString, coder);
|
||||
if (index == 0)
|
||||
return E_INVALIDARG;
|
||||
srcString.DeleteFrontal(index);
|
||||
{
|
||||
unsigned index = ParseStringToUInt32(srcString, coder);
|
||||
if (index == 0)
|
||||
return E_INVALIDARG;
|
||||
srcString.DeleteFrontal(index);
|
||||
}
|
||||
if (srcString[0] == 's')
|
||||
{
|
||||
srcString.Delete(0);
|
||||
int index = ParseStringToUInt32(srcString, stream);
|
||||
unsigned index = ParseStringToUInt32(srcString, stream);
|
||||
if (index == 0)
|
||||
return E_INVALIDARG;
|
||||
srcString.DeleteFrontal(index);
|
||||
|
||||
@@ -1150,9 +1150,8 @@ HRESULT CInArchive::ReadHeader(
|
||||
if (type == NID::kFilesInfo)
|
||||
{
|
||||
|
||||
CNum numFiles = ReadNum();
|
||||
const CNum numFiles = ReadNum();
|
||||
db.Files.ClearAndSetSize(numFiles);
|
||||
CNum i;
|
||||
/*
|
||||
db.Files.Reserve(numFiles);
|
||||
CNum i;
|
||||
@@ -1174,8 +1173,8 @@ HRESULT CInArchive::ReadHeader(
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt64 type = ReadID();
|
||||
if (type == NID::kEnd)
|
||||
const UInt64 type2 = ReadID();
|
||||
if (type2 == NID::kEnd)
|
||||
break;
|
||||
UInt64 size = ReadNumber();
|
||||
if (size > _inByteBack->GetRem())
|
||||
@@ -1184,9 +1183,9 @@ HRESULT CInArchive::ReadHeader(
|
||||
switchProp.Set(this, _inByteBack->GetPtr(), (size_t)size, true);
|
||||
bool addPropIdToList = true;
|
||||
bool isKnownType = true;
|
||||
if (type > ((UInt32)1 << 30))
|
||||
if (type2 > ((UInt32)1 << 30))
|
||||
isKnownType = false;
|
||||
else switch ((UInt32)type)
|
||||
else switch ((UInt32)type2)
|
||||
{
|
||||
case NID::kName:
|
||||
{
|
||||
@@ -1220,7 +1219,7 @@ HRESULT CInArchive::ReadHeader(
|
||||
ReadBoolVector2(db.Files.Size(), boolVector);
|
||||
CStreamSwitch streamSwitch;
|
||||
streamSwitch.Set(this, &dataVector);
|
||||
for (i = 0; i < numFiles; i++)
|
||||
for (CNum i = 0; i < numFiles; i++)
|
||||
{
|
||||
CFileItem &file = db.Files[i];
|
||||
file.AttribDefined = boolVector[i];
|
||||
@@ -1263,7 +1262,7 @@ HRESULT CInArchive::ReadHeader(
|
||||
{
|
||||
ReadBoolVector(numFiles, emptyStreamVector);
|
||||
numEmptyStreams = 0;
|
||||
for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)
|
||||
for (CNum i = 0; i < (CNum)emptyStreamVector.Size(); i++)
|
||||
if (emptyStreamVector[i])
|
||||
numEmptyStreams++;
|
||||
|
||||
@@ -1337,7 +1336,7 @@ HRESULT CInArchive::ReadHeader(
|
||||
if (isKnownType)
|
||||
{
|
||||
if (addPropIdToList)
|
||||
db.ArcInfo.FileInfoPopIDs.Add(type);
|
||||
db.ArcInfo.FileInfoPopIDs.Add(type2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1358,6 +1357,9 @@ HRESULT CInArchive::ReadHeader(
|
||||
CNum sizeIndex = 0;
|
||||
|
||||
CNum numAntiItems = 0;
|
||||
|
||||
CNum i;
|
||||
|
||||
for (i = 0; i < numEmptyStreams; i++)
|
||||
if (antiFileVector[i])
|
||||
numAntiItems++;
|
||||
|
||||
@@ -540,13 +540,13 @@ void COutArchive::WriteHeader(
|
||||
*/
|
||||
_useAlign = true;
|
||||
|
||||
unsigned i;
|
||||
|
||||
UInt64 packedSize = 0;
|
||||
for (i = 0; i < db.PackSizes.Size(); i++)
|
||||
packedSize += db.PackSizes[i];
|
||||
{
|
||||
UInt64 packSize = 0;
|
||||
FOR_VECTOR (i, db.PackSizes)
|
||||
packSize += db.PackSizes[i];
|
||||
headerOffset = packSize;
|
||||
}
|
||||
|
||||
headerOffset = packedSize;
|
||||
|
||||
WriteByte(NID::kHeader);
|
||||
|
||||
@@ -560,7 +560,7 @@ void COutArchive::WriteHeader(
|
||||
|
||||
CRecordVector<UInt64> unpackSizes;
|
||||
CUInt32DefVector digests;
|
||||
for (i = 0; i < db.Files.Size(); i++)
|
||||
FOR_VECTOR (i, db.Files)
|
||||
{
|
||||
const CFileItem &file = db.Files[i];
|
||||
if (!file.HasStream)
|
||||
@@ -588,14 +588,17 @@ void COutArchive::WriteHeader(
|
||||
CBoolVector emptyStreamVector;
|
||||
emptyStreamVector.ClearAndSetSize(db.Files.Size());
|
||||
unsigned numEmptyStreams = 0;
|
||||
for (i = 0; i < db.Files.Size(); i++)
|
||||
if (db.Files[i].HasStream)
|
||||
emptyStreamVector[i] = false;
|
||||
else
|
||||
{
|
||||
emptyStreamVector[i] = true;
|
||||
numEmptyStreams++;
|
||||
}
|
||||
{
|
||||
FOR_VECTOR (i, db.Files)
|
||||
if (db.Files[i].HasStream)
|
||||
emptyStreamVector[i] = false;
|
||||
else
|
||||
{
|
||||
emptyStreamVector[i] = true;
|
||||
numEmptyStreams++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numEmptyStreams != 0)
|
||||
{
|
||||
WritePropBoolVector(NID::kEmptyStream, emptyStreamVector);
|
||||
@@ -605,7 +608,8 @@ void COutArchive::WriteHeader(
|
||||
antiVector.ClearAndSetSize(numEmptyStreams);
|
||||
bool thereAreEmptyFiles = false, thereAreAntiItems = false;
|
||||
unsigned cur = 0;
|
||||
for (i = 0; i < db.Files.Size(); i++)
|
||||
|
||||
FOR_VECTOR (i, db.Files)
|
||||
{
|
||||
const CFileItem &file = db.Files[i];
|
||||
if (file.HasStream)
|
||||
@@ -672,17 +676,21 @@ void COutArchive::WriteHeader(
|
||||
CBoolVector boolVector;
|
||||
boolVector.ClearAndSetSize(db.Files.Size());
|
||||
unsigned numDefined = 0;
|
||||
for (i = 0; i < db.Files.Size(); i++)
|
||||
|
||||
{
|
||||
bool defined = db.Files[i].AttribDefined;
|
||||
boolVector[i] = defined;
|
||||
if (defined)
|
||||
numDefined++;
|
||||
FOR_VECTOR (i, db.Files)
|
||||
{
|
||||
bool defined = db.Files[i].AttribDefined;
|
||||
boolVector[i] = defined;
|
||||
if (defined)
|
||||
numDefined++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numDefined != 0)
|
||||
{
|
||||
WriteAlignedBoolHeader(boolVector, numDefined, NID::kWinAttrib, 4);
|
||||
for (i = 0; i < db.Files.Size(); i++)
|
||||
FOR_VECTOR (i, db.Files)
|
||||
{
|
||||
const CFileItem &file = db.Files[i];
|
||||
if (file.AttribDefined)
|
||||
|
||||
@@ -1681,17 +1681,18 @@ HRESULT Update(
|
||||
}
|
||||
|
||||
UInt64 inSizeForReduce = 0;
|
||||
unsigned i;
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
{
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
if (ui.NewData)
|
||||
FOR_VECTOR (i, updateItems)
|
||||
{
|
||||
complexity += ui.Size;
|
||||
if (numSolidFiles != 1)
|
||||
inSizeForReduce += ui.Size;
|
||||
else if (inSizeForReduce < ui.Size)
|
||||
inSizeForReduce = ui.Size;
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
if (ui.NewData)
|
||||
{
|
||||
complexity += ui.Size;
|
||||
if (numSolidFiles != 1)
|
||||
inSizeForReduce += ui.Size;
|
||||
else if (inSizeForReduce < ui.Size)
|
||||
inSizeForReduce = ui.Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1753,7 +1754,7 @@ HRESULT Update(
|
||||
|
||||
const CCompressionMethodMode &method = *options.Method;
|
||||
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
FOR_VECTOR (i, updateItems)
|
||||
{
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
if (!ui.NewData || !ui.HasStream())
|
||||
@@ -1857,6 +1858,8 @@ HRESULT Update(
|
||||
/* ---------- Write non-AUX dirs and Empty files ---------- */
|
||||
CUIntVector emptyRefs;
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
{
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
@@ -1919,7 +1922,8 @@ HRESULT Update(
|
||||
const CFilterMode2 &filterMode = filters[groupIndex];
|
||||
|
||||
CCompressionMethodMode method = *options.Method;
|
||||
HRESULT res = MakeExeMethod(method, filterMode,
|
||||
{
|
||||
HRESULT res = MakeExeMethod(method, filterMode,
|
||||
#ifdef _7ZIP_ST
|
||||
false
|
||||
#else
|
||||
@@ -1927,7 +1931,8 @@ HRESULT Update(
|
||||
#endif
|
||||
);
|
||||
|
||||
RINOK(res);
|
||||
RINOK(res);
|
||||
}
|
||||
|
||||
if (filterMode.Encrypted)
|
||||
{
|
||||
@@ -2266,8 +2271,12 @@ HRESULT Update(
|
||||
CRecordVector<CRefItem> refItems;
|
||||
refItems.ClearAndSetSize(numFiles);
|
||||
bool sortByType = (options.UseTypeSorting && numSolidFiles > 1);
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < numFiles; i++)
|
||||
refItems[i] = CRefItem(group.Indices[i], updateItems[group.Indices[i]], sortByType);
|
||||
|
||||
CSortParam sortParam;
|
||||
// sortParam.TreeFolders = &treeFolders;
|
||||
sortParam.SortByType = sortByType;
|
||||
|
||||
@@ -343,16 +343,17 @@ HRESULT CHandler::ParseLongNames(IInStream *stream)
|
||||
if (item.Size > ((UInt32)1 << 30))
|
||||
return S_FALSE;
|
||||
RINOK(stream->Seek(item.GetDataPos(), STREAM_SEEK_SET, NULL));
|
||||
size_t size = (size_t)item.Size;
|
||||
const size_t size = (size_t)item.Size;
|
||||
|
||||
CByteArr p(size);
|
||||
RINOK(ReadStream_FALSE(stream, p, size));
|
||||
|
||||
for (i = 0; i < _items.Size(); i++)
|
||||
{
|
||||
CItem &item = _items[i];
|
||||
if (item.Name[0] != '/')
|
||||
CItem &item2 = _items[i];
|
||||
if (item2.Name[0] != '/')
|
||||
continue;
|
||||
const char *ptr = item.Name.Ptr(1);
|
||||
const char *ptr = item2.Name.Ptr(1);
|
||||
const char *end;
|
||||
UInt32 pos = ConvertStringToUInt32(ptr, &end);
|
||||
if (*end != 0 || end == ptr)
|
||||
@@ -369,8 +370,9 @@ HRESULT CHandler::ParseLongNames(IInStream *stream)
|
||||
break;
|
||||
pos++;
|
||||
}
|
||||
item.Name.SetFrom((const char *)(p + start), pos - start);
|
||||
item2.Name.SetFrom((const char *)(p + start), pos - start);
|
||||
}
|
||||
|
||||
_longNames_FileIndex = fileIndex;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -1017,11 +1017,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
for (; i < numItems; i++)
|
||||
{
|
||||
unsigned indexNext = allFilesMode ? i : indices[i];
|
||||
const CMvItem &mvItem = m_Database.Items[indexNext];
|
||||
const CItem &item = m_Database.Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
|
||||
if (item.IsDir())
|
||||
const CMvItem &mvItem2 = m_Database.Items[indexNext];
|
||||
const CItem &item2 = m_Database.Volumes[mvItem2.VolumeIndex].Items[mvItem2.ItemIndex];
|
||||
if (item2.IsDir())
|
||||
continue;
|
||||
int newFolderIndex = m_Database.GetFolderIndex(&mvItem);
|
||||
int newFolderIndex = m_Database.GetFolderIndex(&mvItem2);
|
||||
|
||||
if (newFolderIndex != folderIndex)
|
||||
break;
|
||||
@@ -1029,7 +1029,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
extractStatuses.Add(false);
|
||||
extractStatuses.Add(true);
|
||||
startIndex++;
|
||||
curUnpack = item.GetEndOffset();
|
||||
curUnpack = item2.GetEndOffset();
|
||||
}
|
||||
|
||||
CFolderOutStream *cabFolderOutStream = new CFolderOutStream;
|
||||
@@ -1104,16 +1104,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
break;
|
||||
}
|
||||
|
||||
const CDatabaseEx &db = m_Database.Volumes[volIndex];
|
||||
const CFolder &folder = db.Folders[locFolderIndex];
|
||||
const CDatabaseEx &db2 = m_Database.Volumes[volIndex];
|
||||
const CFolder &folder2 = db2.Folders[locFolderIndex];
|
||||
|
||||
if (bl == 0)
|
||||
{
|
||||
cabBlockInStreamSpec->ReservedSize = db.ArcInfo.GetDataBlockReserveSize();
|
||||
RINOK(db.Stream->Seek(db.StartPosition + folder.DataStart, STREAM_SEEK_SET, NULL));
|
||||
cabBlockInStreamSpec->ReservedSize = db2.ArcInfo.GetDataBlockReserveSize();
|
||||
RINOK(db2.Stream->Seek(db2.StartPosition + folder2.DataStart, STREAM_SEEK_SET, NULL));
|
||||
}
|
||||
|
||||
if (bl == folder.NumDataBlocks)
|
||||
if (bl == folder2.NumDataBlocks)
|
||||
{
|
||||
/*
|
||||
CFolder::NumDataBlocks (CFFOLDER::cCFData in CAB specification) is 16-bit.
|
||||
@@ -1138,7 +1138,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
cabBlockInStreamSpec->InitForNewBlock();
|
||||
|
||||
UInt32 packSize, unpackSize;
|
||||
res = cabBlockInStreamSpec->PreRead(db.Stream, packSize, unpackSize);
|
||||
res = cabBlockInStreamSpec->PreRead(db2.Stream, packSize, unpackSize);
|
||||
if (res == S_FALSE)
|
||||
break;
|
||||
RINOK(res);
|
||||
@@ -1180,7 +1180,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
UInt64 unpackSize64 = unpackSize;
|
||||
UInt32 packSizeChunk = cabBlockInStreamSpec->GetPackSizeAvail();
|
||||
|
||||
switch (folder.GetMethod())
|
||||
switch (folder2.GetMethod())
|
||||
{
|
||||
case NHeader::NMethod::kNone:
|
||||
res = copyCoder->Code(cabBlockInStream, outStream, NULL, &unpackSize64, NULL);
|
||||
|
||||
@@ -154,7 +154,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
case kpidBlock:
|
||||
if (m_Database.LowLevel)
|
||||
prop = item.Section;
|
||||
else if (item.Section != 0)
|
||||
else if (item.Section != 0 && item.Section < m_Database.Sections.Size())
|
||||
prop = m_Database.GetFolder(index);
|
||||
break;
|
||||
|
||||
@@ -545,7 +545,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
currentTotalSize += item.Size;
|
||||
continue;
|
||||
}
|
||||
const CSectionInfo §ion = m_Database.Sections[(unsigned)item.Section];
|
||||
|
||||
if (sectionIndex >= m_Database.Sections.Size())
|
||||
continue;
|
||||
|
||||
const CSectionInfo §ion = m_Database.Sections[(unsigned)sectionIndex];
|
||||
if (section.IsLzx())
|
||||
{
|
||||
const CLzxInfo &lzxInfo = section.Methods[0].LzxInfo;
|
||||
@@ -621,6 +625,18 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sectionIndex >= m_Database.Sections.Size())
|
||||
{
|
||||
// we must report error here;
|
||||
CMyComPtr<ISequentialOutStream> realOutStream;
|
||||
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
|
||||
if (!testMode && !realOutStream)
|
||||
continue;
|
||||
RINOK(extractCallback->PrepareOperation(askMode));
|
||||
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kHeadersError));
|
||||
continue;
|
||||
}
|
||||
|
||||
const CSectionInfo §ion = m_Database.Sections[(unsigned)sectionIndex];
|
||||
|
||||
if (!section.IsLzx())
|
||||
|
||||
@@ -667,13 +667,15 @@ static int CompareFiles(const unsigned *p1, const unsigned *p2, void *param)
|
||||
return -1;
|
||||
if (isDir2)
|
||||
{
|
||||
if (isDir1)
|
||||
return MyCompare(*p1, *p2);
|
||||
return 1;
|
||||
if (!isDir1)
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOZ(MyCompare(item1.Section, item2.Section));
|
||||
RINOZ(MyCompare(item1.Offset, item2.Offset));
|
||||
RINOZ(MyCompare(item1.Size, item2.Size));
|
||||
}
|
||||
RINOZ(MyCompare(item1.Section, item2.Section));
|
||||
RINOZ(MyCompare(item1.Offset, item2.Offset));
|
||||
RINOZ(MyCompare(item1.Size, item2.Size));
|
||||
return MyCompare(*p1, *p2);
|
||||
}
|
||||
|
||||
@@ -716,6 +718,19 @@ bool CFilesDatabase::Check()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFilesDatabase::CheckSectionRefs()
|
||||
{
|
||||
FOR_VECTOR (i, Indices)
|
||||
{
|
||||
const CItem &item = Items[Indices[i]];
|
||||
if (item.Section == 0 || item.IsDir())
|
||||
continue;
|
||||
if (item.Section >= Sections.Size())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int inline GetLog(UInt32 num)
|
||||
{
|
||||
for (int i = 0; i < 32; i++)
|
||||
@@ -745,10 +760,10 @@ HRESULT CInArchive::OpenHighLevel(IInStream *inStream, CFilesDatabase &database)
|
||||
}
|
||||
}
|
||||
|
||||
unsigned i;
|
||||
for (i = 1; i < database.Sections.Size(); i++)
|
||||
unsigned si;
|
||||
for (si = 1; si < database.Sections.Size(); si++)
|
||||
{
|
||||
CSectionInfo §ion = database.Sections[i];
|
||||
CSectionInfo §ion = database.Sections[si];
|
||||
AString sectionPrefix = GetSectionPrefix(section.Name);
|
||||
{
|
||||
// Content
|
||||
@@ -993,6 +1008,8 @@ HRESULT CInArchive::Open2(IInStream *inStream,
|
||||
return S_OK;
|
||||
}
|
||||
RINOK(res);
|
||||
if (!database.CheckSectionRefs())
|
||||
HeadersError = true;
|
||||
database.LowLevel = false;
|
||||
}
|
||||
catch(...)
|
||||
|
||||
@@ -186,18 +186,24 @@ public:
|
||||
UInt64 GetFolder(unsigned fileIndex) const
|
||||
{
|
||||
const CItem &item = Items[Indices[fileIndex]];
|
||||
const CSectionInfo §ion = Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
return section.Methods[0].LzxInfo.GetFolder(item.Offset);
|
||||
if (item.Section < Sections.Size())
|
||||
{
|
||||
const CSectionInfo §ion = Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
return section.Methods[0].LzxInfo.GetFolder(item.Offset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
UInt64 GetLastFolder(unsigned fileIndex) const
|
||||
{
|
||||
const CItem &item = Items[Indices[fileIndex]];
|
||||
const CSectionInfo §ion = Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1);
|
||||
if (item.Section < Sections.Size())
|
||||
{
|
||||
const CSectionInfo §ion = Sections[(unsigned)item.Section];
|
||||
if (section.IsLzx())
|
||||
return section.Methods[0].LzxInfo.GetFolder(item.Offset + item.Size - 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -217,6 +223,7 @@ public:
|
||||
void SetIndices();
|
||||
void Sort();
|
||||
bool Check();
|
||||
bool CheckSectionRefs();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ HRESULT CDatabase::ReadSector(IInStream *inStream, Byte *buf, unsigned sectorSiz
|
||||
{
|
||||
UpdatePhySize(((UInt64)sid + 2) << sectorSizeBits);
|
||||
RINOK(inStream->Seek((((UInt64)sid + 1) << sectorSizeBits), STREAM_SEEK_SET, NULL));
|
||||
return ReadStream_FALSE(inStream, buf, (UInt32)1 << sectorSizeBits);
|
||||
return ReadStream_FALSE(inStream, buf, (size_t)1 << sectorSizeBits);
|
||||
}
|
||||
|
||||
HRESULT CDatabase::ReadIDs(IInStream *inStream, Byte *buf, unsigned sectorSizeBits, UInt32 sid, UInt32 *dest)
|
||||
|
||||
@@ -81,7 +81,7 @@ HRESULT CMultiMethodProps::SetProperty(const wchar_t *nameSpec, const PROPVARIAN
|
||||
}
|
||||
|
||||
UInt32 number;
|
||||
int index = ParseStringToUInt32(name, number);
|
||||
unsigned index = ParseStringToUInt32(name, number);
|
||||
UString realName = name.Ptr(index);
|
||||
if (index == 0)
|
||||
{
|
||||
|
||||
@@ -583,13 +583,13 @@ HRESULT CHandler::ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize)
|
||||
}
|
||||
}
|
||||
|
||||
bool be = _h.be;
|
||||
const Byte *p = _data + (_curBlocksOffset + (UInt32)blockIndex * 4);
|
||||
UInt32 start = (blockIndex == 0 ? _curBlocksOffset + _curNumBlocks * 4: Get32(p - 4));
|
||||
UInt32 end = Get32(p);
|
||||
const bool be = _h.be;
|
||||
const Byte *p2 = _data + (_curBlocksOffset + (UInt32)blockIndex * 4);
|
||||
const UInt32 start = (blockIndex == 0 ? _curBlocksOffset + _curNumBlocks * 4: Get32(p2 - 4));
|
||||
const UInt32 end = Get32(p2);
|
||||
if (end < start || end > _size)
|
||||
return S_FALSE;
|
||||
UInt32 inSize = end - start;
|
||||
const UInt32 inSize = end - start;
|
||||
|
||||
if (_method == k_Flags_Method_LZMA)
|
||||
{
|
||||
@@ -707,7 +707,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
RINOK(hres);
|
||||
{
|
||||
HRESULT hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
if (hres == S_OK)
|
||||
{
|
||||
if (copyCoderSpec->TotalSize == curSize)
|
||||
|
||||
@@ -2810,7 +2810,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
RINOK(hres);
|
||||
{
|
||||
HRESULT hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
if (hres == S_OK)
|
||||
{
|
||||
if (copyCoderSpec->TotalSize == unpackSize)
|
||||
|
||||
@@ -876,7 +876,7 @@ HRESULT CDatabase::LoadCatalog(const CFork &fork, const CObjectVector<CIdExtents
|
||||
// CNodeDescriptor nodeDesc;
|
||||
// nodeDesc.Parse(p);
|
||||
CHeaderRec hr;
|
||||
hr.Parse(p + kNodeDescriptor_Size);
|
||||
RINOK(hr.Parse(p + kNodeDescriptor_Size));
|
||||
|
||||
// CaseSensetive = (Header.IsHfsX() && hr.KeyCompareType == 0xBC);
|
||||
|
||||
@@ -1764,7 +1764,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
if (rem == 0)
|
||||
{
|
||||
// Here we check that there are no extra (empty) blocks in last extent.
|
||||
if (extentRem >= (UInt64)((UInt32)1 << Header.BlockSizeLog))
|
||||
if (extentRem >= ((UInt64)1 << Header.BlockSizeLog))
|
||||
res = NExtract::NOperationResult::kDataError;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
UInt64 blockIndex;
|
||||
UInt64 currentItemSize;
|
||||
|
||||
if (index < (UInt32)_archive.Refs.Size())
|
||||
if (index < _archive.Refs.Size())
|
||||
{
|
||||
const CRef &ref = _archive.Refs[index];
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index];
|
||||
@@ -375,14 +375,14 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
UInt64 virtOffset = 0;
|
||||
for (UInt32 i = 0; i < ref.NumExtents; i++)
|
||||
{
|
||||
const CDir &item = ref.Dir->_subItems[ref.Index + i];
|
||||
if (item.Size == 0)
|
||||
const CDir &item2 = ref.Dir->_subItems[ref.Index + i];
|
||||
if (item2.Size == 0)
|
||||
continue;
|
||||
CSeekExtent se;
|
||||
se.Phy = (UInt64)item.ExtentLocation * kBlockSize;
|
||||
se.Phy = (UInt64)item2.ExtentLocation * kBlockSize;
|
||||
se.Virt = virtOffset;
|
||||
extentStreamSpec->Extents.Add(se);
|
||||
virtOffset += item.Size;
|
||||
virtOffset += item2.Size;
|
||||
}
|
||||
if (virtOffset != ref.TotalSize)
|
||||
return S_FALSE;
|
||||
@@ -394,6 +394,7 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
|
||||
*stream = extentStream.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
currentItemSize = item.Size;
|
||||
blockIndex = item.ExtentLocation;
|
||||
}
|
||||
|
||||
@@ -630,24 +630,27 @@ static size_t Lznt1Dec(Byte *dest, size_t outBufLim, size_t destLen, const Byte
|
||||
{
|
||||
if (srcLen < 2 || (destSize & 0xFFF) != 0)
|
||||
break;
|
||||
UInt32 v = Get16(src);
|
||||
if (v == 0)
|
||||
break;
|
||||
src += 2;
|
||||
srcLen -= 2;
|
||||
UInt32 comprSize = (v & 0xFFF) + 1;
|
||||
if (comprSize > srcLen)
|
||||
break;
|
||||
srcLen -= comprSize;
|
||||
if ((v & 0x8000) == 0)
|
||||
UInt32 comprSize;
|
||||
{
|
||||
if (comprSize != (1 << 12))
|
||||
const UInt32 v = Get16(src);
|
||||
if (v == 0)
|
||||
break;
|
||||
memcpy(dest + destSize, src, comprSize);
|
||||
src += comprSize;
|
||||
destSize += comprSize;
|
||||
src += 2;
|
||||
srcLen -= 2;
|
||||
comprSize = (v & 0xFFF) + 1;
|
||||
if (comprSize > srcLen)
|
||||
break;
|
||||
srcLen -= comprSize;
|
||||
if ((v & 0x8000) == 0)
|
||||
{
|
||||
if (comprSize != (1 << 12))
|
||||
break;
|
||||
memcpy(dest + destSize, src, comprSize);
|
||||
src += comprSize;
|
||||
destSize += comprSize;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (destSize + (1 << 12) > outBufLim || (src[0] & 1) != 0)
|
||||
return 0;
|
||||
@@ -672,7 +675,7 @@ static size_t Lznt1Dec(Byte *dest, size_t outBufLim, size_t destLen, const Byte
|
||||
{
|
||||
if (comprSize < 2)
|
||||
return 0;
|
||||
UInt32 v = Get16(src + pos);
|
||||
const UInt32 v = Get16(src + pos);
|
||||
pos += 2;
|
||||
comprSize -= 2;
|
||||
|
||||
@@ -709,9 +712,12 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
return (Size == _virtPos) ? S_OK: E_FAIL;
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
UInt64 rem = Size - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
{
|
||||
const UInt64 rem = Size - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
}
|
||||
|
||||
if (_virtPos >= InitializedSize)
|
||||
{
|
||||
memset((Byte *)data, 0, size);
|
||||
@@ -719,9 +725,12 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
}
|
||||
rem = InitializedSize - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
|
||||
{
|
||||
const UInt64 rem = InitializedSize - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
}
|
||||
|
||||
while (_curRem == 0)
|
||||
{
|
||||
@@ -838,7 +847,7 @@ STDMETHODIMP CInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
}
|
||||
size_t destLenMax = GetCuSize();
|
||||
size_t destLen = destLenMax;
|
||||
UInt64 rem = Size - (virtBlock2 << BlockSizeLog);
|
||||
const UInt64 rem = Size - (virtBlock2 << BlockSizeLog);
|
||||
if (destLen > rem)
|
||||
destLen = (size_t)rem;
|
||||
|
||||
@@ -895,10 +904,13 @@ STDMETHODIMP CInStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPositio
|
||||
static HRESULT DataParseExtents(unsigned clusterSizeLog, const CObjectVector<CAttr> &attrs,
|
||||
unsigned attrIndex, unsigned attrIndexLim, UInt64 numPhysClusters, CRecordVector<CExtent> &Extents)
|
||||
{
|
||||
CExtent e;
|
||||
e.Virt = 0;
|
||||
e.Phy = kEmptyExtent;
|
||||
Extents.Add(e);
|
||||
{
|
||||
CExtent e;
|
||||
e.Virt = 0;
|
||||
e.Phy = kEmptyExtent;
|
||||
Extents.Add(e);
|
||||
}
|
||||
|
||||
const CAttr &attr0 = attrs[attrIndex];
|
||||
|
||||
if (attr0.AllocatedSize < attr0.Size ||
|
||||
@@ -1075,20 +1087,22 @@ HRESULT CMftRec::GetStream(IInStream *mainStream, int dataIndex,
|
||||
{
|
||||
if (numNonResident != ref.Num || !attr0.IsCompressionUnitSupported())
|
||||
return S_FALSE;
|
||||
CInStream *streamSpec = new CInStream;
|
||||
CMyComPtr<IInStream> streamTemp = streamSpec;
|
||||
RINOK(DataParseExtents(clusterSizeLog, DataAttrs, ref.Start, ref.Start + ref.Num, numPhysClusters, streamSpec->Extents));
|
||||
streamSpec->Size = attr0.Size;
|
||||
streamSpec->InitializedSize = attr0.InitializedSize;
|
||||
streamSpec->Stream = mainStream;
|
||||
streamSpec->BlockSizeLog = clusterSizeLog;
|
||||
streamSpec->InUse = InUse();
|
||||
RINOK(streamSpec->InitAndSeek(attr0.CompressionUnit));
|
||||
*destStream = streamTemp.Detach();
|
||||
CInStream *ss = new CInStream;
|
||||
CMyComPtr<IInStream> streamTemp2 = ss;
|
||||
RINOK(DataParseExtents(clusterSizeLog, DataAttrs, ref.Start, ref.Start + ref.Num, numPhysClusters, ss->Extents));
|
||||
ss->Size = attr0.Size;
|
||||
ss->InitializedSize = attr0.InitializedSize;
|
||||
ss->Stream = mainStream;
|
||||
ss->BlockSizeLog = clusterSizeLog;
|
||||
ss->InUse = InUse();
|
||||
RINOK(ss->InitAndSeek(attr0.CompressionUnit));
|
||||
*destStream = streamTemp2.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
streamSpec->Buf = attr0.Data;
|
||||
}
|
||||
|
||||
streamSpec->Init();
|
||||
*destStream = streamTemp.Detach();
|
||||
return S_OK;
|
||||
@@ -1691,36 +1705,40 @@ HRESULT CDatabase::Open()
|
||||
if ((mftSize >> 4) > Header.GetPhySize_Clusters())
|
||||
return S_FALSE;
|
||||
|
||||
UInt64 numFiles = mftSize >> RecSizeLog;
|
||||
if (numFiles > (1 << 30))
|
||||
return S_FALSE;
|
||||
if (OpenCallback)
|
||||
{
|
||||
RINOK(OpenCallback->SetTotal(&numFiles, &mftSize));
|
||||
}
|
||||
|
||||
const size_t kBufSize = (1 << 15);
|
||||
const size_t recSize = ((size_t)1 << RecSizeLog);
|
||||
if (kBufSize < recSize)
|
||||
return S_FALSE;
|
||||
|
||||
ByteBuf.Alloc(kBufSize);
|
||||
Recs.ClearAndReserve((unsigned)numFiles);
|
||||
{
|
||||
const UInt64 numFiles = mftSize >> RecSizeLog;
|
||||
if (numFiles > (1 << 30))
|
||||
return S_FALSE;
|
||||
if (OpenCallback)
|
||||
{
|
||||
RINOK(OpenCallback->SetTotal(&numFiles, &mftSize));
|
||||
}
|
||||
|
||||
ByteBuf.Alloc(kBufSize);
|
||||
Recs.ClearAndReserve((unsigned)numFiles);
|
||||
}
|
||||
|
||||
for (UInt64 pos64 = 0;;)
|
||||
{
|
||||
if (OpenCallback)
|
||||
{
|
||||
UInt64 numFiles = Recs.Size();
|
||||
const UInt64 numFiles = Recs.Size();
|
||||
if ((numFiles & 0x3FF) == 0)
|
||||
{
|
||||
RINOK(OpenCallback->SetCompleted(&numFiles, &pos64));
|
||||
}
|
||||
}
|
||||
size_t readSize = kBufSize;
|
||||
UInt64 rem = mftSize - pos64;
|
||||
if (readSize > rem)
|
||||
readSize = (size_t)rem;
|
||||
{
|
||||
const UInt64 rem = mftSize - pos64;
|
||||
if (readSize > rem)
|
||||
readSize = (size_t)rem;
|
||||
}
|
||||
if (readSize < recSize)
|
||||
break;
|
||||
RINOK(ReadStream_FALSE(mftStream, ByteBuf, readSize));
|
||||
@@ -2668,7 +2686,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
RINOK(hres);
|
||||
if (inStream)
|
||||
{
|
||||
HRESULT hres = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
|
||||
hres = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
|
||||
if (hres != S_OK && hres != S_FALSE)
|
||||
{
|
||||
RINOK(hres);
|
||||
|
||||
@@ -242,7 +242,7 @@ struct COptHeader
|
||||
|
||||
int GetNumFileAlignBits() const
|
||||
{
|
||||
for (int i = 9; i <= 16; i++)
|
||||
for (unsigned i = 0; i <= 31; i++)
|
||||
if (((UInt32)1 << i) == FileAlign)
|
||||
return i;
|
||||
return -1;
|
||||
@@ -1154,7 +1154,7 @@ HRESULT CHandler::ReadTable(UInt32 offset, CRecordVector<CTableItem> &items)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static const UInt32 kFileSizeMax = (UInt32)1 << 30;
|
||||
static const UInt32 kFileSizeMax = (UInt32)1 << 31;
|
||||
static const unsigned kNumResItemsMax = (unsigned)1 << 23;
|
||||
static const unsigned kNumStringLangsMax = 256;
|
||||
|
||||
@@ -1898,25 +1898,61 @@ static bool ParseVersion(const Byte *p, UInt32 size, CTextFile &f, CObjectVector
|
||||
HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchiveOpenCallback *callback)
|
||||
{
|
||||
const CSection § = _sections[sectionIndex];
|
||||
const size_t fileSize = sect.GetSizeMin();
|
||||
|
||||
if (fileSize > kFileSizeMax)
|
||||
return S_FALSE;
|
||||
size_t fileSize = sect.PSize;
|
||||
{
|
||||
UInt64 fileSize64 = fileSize;
|
||||
if (callback)
|
||||
RINOK(callback->SetTotal(NULL, &fileSize64));
|
||||
RINOK(stream->Seek(sect.Pa, STREAM_SEEK_SET, NULL));
|
||||
_buf.Alloc(fileSize);
|
||||
for (size_t pos = 0; pos < fileSize;)
|
||||
size_t fileSizeMin = sect.PSize;
|
||||
|
||||
if (sect.VSize < sect.PSize)
|
||||
{
|
||||
UInt64 offset64 = pos;
|
||||
fileSize = fileSizeMin = sect.VSize;
|
||||
const int numBits = _optHeader.GetNumFileAlignBits();
|
||||
if (numBits > 0)
|
||||
{
|
||||
const UInt32 mask = ((UInt32)1 << numBits) - 1;
|
||||
const size_t end = (size_t)((sect.VSize + mask) & (UInt32)~mask);
|
||||
if (end > sect.VSize)
|
||||
if (end <= sect.PSize)
|
||||
fileSize = end;
|
||||
else
|
||||
fileSize = sect.PSize;
|
||||
}
|
||||
}
|
||||
|
||||
if (fileSize > kFileSizeMax)
|
||||
return S_FALSE;
|
||||
|
||||
{
|
||||
const UInt64 fileSize64 = fileSize;
|
||||
if (callback)
|
||||
RINOK(callback->SetCompleted(NULL, &offset64))
|
||||
RINOK(callback->SetTotal(NULL, &fileSize64));
|
||||
}
|
||||
|
||||
RINOK(stream->Seek(sect.Pa, STREAM_SEEK_SET, NULL));
|
||||
|
||||
_buf.Alloc(fileSize);
|
||||
|
||||
size_t pos;
|
||||
|
||||
for (pos = 0; pos < fileSize;)
|
||||
{
|
||||
{
|
||||
const UInt64 offset64 = pos;
|
||||
if (callback)
|
||||
RINOK(callback->SetCompleted(NULL, &offset64))
|
||||
}
|
||||
size_t rem = MyMin(fileSize - pos, (size_t)(1 << 22));
|
||||
RINOK(ReadStream_FALSE(stream, _buf + pos, rem));
|
||||
RINOK(ReadStream(stream, _buf + pos, &rem));
|
||||
if (rem == 0)
|
||||
{
|
||||
if (pos < fileSizeMin)
|
||||
return S_FALSE;
|
||||
break;
|
||||
}
|
||||
pos += rem;
|
||||
}
|
||||
|
||||
if (pos < fileSize)
|
||||
memset(_buf + pos, 0, fileSize - pos);
|
||||
}
|
||||
|
||||
_usedRes.Alloc(fileSize);
|
||||
@@ -2037,19 +2073,13 @@ HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchi
|
||||
|
||||
_usedRes.Free();
|
||||
|
||||
int numBits = _optHeader.GetNumFileAlignBits();
|
||||
if (numBits >= 0)
|
||||
{
|
||||
UInt32 mask = (1 << numBits) - 1;
|
||||
size_t end = ((maxOffset + mask) & ~mask);
|
||||
|
||||
// PSize can be much larger than VSize in some exe installers.
|
||||
// it contains archive data after PE resources.
|
||||
// So we need to use PSize here!
|
||||
if (/* end < sect.VSize && */ end <= sect.PSize)
|
||||
if (maxOffset < sect.PSize)
|
||||
{
|
||||
CSection sect2;
|
||||
sect2.Flags = 0;
|
||||
size_t end = fileSize;
|
||||
|
||||
// we skip Zeros to start of aligned block
|
||||
size_t i;
|
||||
@@ -2059,6 +2089,8 @@ HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchi
|
||||
if (i == end)
|
||||
maxOffset = end;
|
||||
|
||||
CSection sect2;
|
||||
sect2.Flags = 0;
|
||||
sect2.Pa = sect.Pa + (UInt32)maxOffset;
|
||||
sect2.Va = sect.Va + (UInt32)maxOffset;
|
||||
|
||||
@@ -2211,14 +2243,14 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
|
||||
}
|
||||
*/
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < processed; i++)
|
||||
if (buf[i] != 0)
|
||||
size_t k;
|
||||
for (k = 0; k < processed; k++)
|
||||
if (buf[k] != 0)
|
||||
break;
|
||||
if (processed < size && processed < 100)
|
||||
_totalSize += (UInt32)processed;
|
||||
else if (((_totalSize + i) & 0x1FF) == 0 || processed < size)
|
||||
_totalSize += (UInt32)i;
|
||||
else if (((_totalSize + k) & 0x1FF) == 0 || processed < size)
|
||||
_totalSize += (UInt32)k;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2248,9 +2280,9 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
|
||||
sections.Sort();
|
||||
UInt32 limit = (1 << 12);
|
||||
unsigned num = 0;
|
||||
FOR_VECTOR (i, sections)
|
||||
FOR_VECTOR (k, sections)
|
||||
{
|
||||
const CSection &s = sections[i];
|
||||
const CSection &s = sections[k];
|
||||
if (s.Pa > limit)
|
||||
{
|
||||
CSection &s2 = _sections.AddNew();
|
||||
|
||||
@@ -463,22 +463,26 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *openCallback)
|
||||
RINOK(openCallback->SetCompleted(NULL, &numBytes));
|
||||
}
|
||||
|
||||
UInt64 v = Get64((const Byte *)table + (size_t)i * 8);
|
||||
v &= offsetMask;
|
||||
CByteBuffer &buf = _tables.AddNew();
|
||||
if (v == 0)
|
||||
continue;
|
||||
CByteBuffer &buf2 = _tables.AddNew();
|
||||
|
||||
{
|
||||
UInt64 v = Get64((const Byte *)table + (size_t)i * 8);
|
||||
v &= offsetMask;
|
||||
if (v == 0)
|
||||
continue;
|
||||
|
||||
buf2.Alloc((size_t)1 << (_numMidBits + 3));
|
||||
RINOK(stream->Seek(v, STREAM_SEEK_SET, NULL));
|
||||
RINOK(ReadStream_FALSE(stream, buf2, clusterSize));
|
||||
|
||||
buf.Alloc((size_t)1 << (_numMidBits + 3));
|
||||
RINOK(stream->Seek(v, STREAM_SEEK_SET, NULL));
|
||||
RINOK(ReadStream_FALSE(stream, buf, clusterSize));
|
||||
UInt64 end = v + clusterSize;
|
||||
if (_phySize < end)
|
||||
_phySize = end;
|
||||
const UInt64 end = v + clusterSize;
|
||||
if (_phySize < end)
|
||||
_phySize = end;
|
||||
}
|
||||
|
||||
for (size_t k = 0; k < clusterSize; k += 8)
|
||||
{
|
||||
UInt64 v = Get64((const Byte *)buf + (size_t)k);
|
||||
const UInt64 v = Get64((const Byte *)buf2 + (size_t)k);
|
||||
if (v == 0)
|
||||
continue;
|
||||
UInt64 offset = v & offsetMask;
|
||||
|
||||
@@ -189,8 +189,8 @@ bool CItem::FindExtra_Version(UInt64 &version) const
|
||||
return false;
|
||||
const Byte *p = Extra + (unsigned)offset;
|
||||
|
||||
UInt64 Flags;
|
||||
unsigned num = ReadVarInt(p, size, &Flags);
|
||||
UInt64 flags;
|
||||
unsigned num = ReadVarInt(p, size, &flags);
|
||||
if (num == 0) return false; p += num; size -= num;
|
||||
|
||||
num = ReadVarInt(p, size, &version);
|
||||
@@ -1881,6 +1881,7 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
}
|
||||
|
||||
CInArcInfo arcInfoOpen;
|
||||
{
|
||||
HRESULT res = arch.Open(inStream, maxCheckStartPosition, getTextPassword, arcInfoOpen);
|
||||
if (arch.IsArc && arch.UnexpectedEnd)
|
||||
_errorFlags |= kpv_ErrorFlags_UnexpectedEnd;
|
||||
@@ -1897,6 +1898,7 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
return res;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CArc &arc = _arcs.AddNew();
|
||||
CInArcInfo &arcInfo = arc.Info;
|
||||
@@ -2068,12 +2070,12 @@ HRESULT CHandler::Open2(IInStream *stream,
|
||||
{
|
||||
if (prevSplitFile >= 0)
|
||||
{
|
||||
CRefItem &ref = _refs[prevSplitFile];
|
||||
CItem &prevItem = _items[ref.Last];
|
||||
CRefItem &ref2 = _refs[prevSplitFile];
|
||||
CItem &prevItem = _items[ref2.Last];
|
||||
if (item.IsNextForItem(prevItem))
|
||||
{
|
||||
ref.Last = _items.Size();
|
||||
prevItem.NextItem = ref.Last;
|
||||
ref2.Last = _items.Size();
|
||||
prevItem.NextItem = ref2.Last;
|
||||
needAdd = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1602,11 +1602,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
if (len > kPasswordLen_MAX)
|
||||
len = kPasswordLen_MAX;
|
||||
CByteArr buffer(len * 2);
|
||||
for (unsigned i = 0; i < len; i++)
|
||||
for (unsigned k = 0; k < len; k++)
|
||||
{
|
||||
wchar_t c = password[i];
|
||||
((Byte *)buffer)[i * 2] = (Byte)c;
|
||||
((Byte *)buffer)[i * 2 + 1] = (Byte)(c >> 8);
|
||||
wchar_t c = password[k];
|
||||
((Byte *)buffer)[k * 2] = (Byte)c;
|
||||
((Byte *)buffer)[k * 2 + 1] = (Byte)(c >> 8);
|
||||
}
|
||||
rar3CryptoDecoderSpec->SetPassword((const Byte *)buffer, len * 2);
|
||||
}
|
||||
|
||||
@@ -296,23 +296,25 @@ struct CNode
|
||||
|
||||
UInt32 CNode::Parse1(const Byte *p, UInt32 size, const CHeader &_h)
|
||||
{
|
||||
bool be = _h.be;
|
||||
const bool be = _h.be;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
UInt16 t = Get16(p);
|
||||
if (be)
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
Uid = (UInt16)(p[2] >> 4);
|
||||
Gid = (UInt16)(p[2] & 0xF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
Uid = (UInt16)(p[2] & 0xF);
|
||||
Gid = (UInt16)(p[2] >> 4);
|
||||
const UInt32 t = Get16(p);
|
||||
if (be)
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
Uid = (UInt16)(p[2] >> 4);
|
||||
Gid = (UInt16)(p[2] & 0xF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
Uid = (UInt16)(p[2] & 0xF);
|
||||
Gid = (UInt16)(p[2] >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
// Xattr = kXattr_Empty;
|
||||
@@ -402,17 +404,20 @@ UInt32 CNode::Parse2(const Byte *p, UInt32 size, const CHeader &_h)
|
||||
bool be = _h.be;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
UInt16 t = Get16(p);
|
||||
if (be)
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
const UInt32 t = Get16(p);
|
||||
if (be)
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
Uid = p[2];
|
||||
Gid = p[3];
|
||||
|
||||
@@ -532,17 +537,21 @@ UInt32 CNode::Parse3(const Byte *p, UInt32 size, const CHeader &_h)
|
||||
bool be = _h.be;
|
||||
if (size < 12)
|
||||
return 0;
|
||||
UInt16 t = Get16(p);
|
||||
if (be)
|
||||
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
const UInt32 t = Get16(p);
|
||||
if (be)
|
||||
{
|
||||
Type = (UInt16)(t >> 12);
|
||||
Mode = (UInt16)(t & 0xFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = (UInt16)(t & 0xF);
|
||||
Mode = (UInt16)(t >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
Uid = p[2];
|
||||
Gid = p[3];
|
||||
// GET_32 (4, MTime);
|
||||
@@ -2115,7 +2124,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
|
||||
{
|
||||
RINOK(hres);
|
||||
{
|
||||
HRESULT hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
hres = copyCoder->Code(inSeqStream, outStream, NULL, NULL, progress);
|
||||
if (hres == S_OK)
|
||||
{
|
||||
if (copyCoderSpec->TotalSize == unpackSize)
|
||||
|
||||
@@ -428,7 +428,7 @@ HRESULT CInArchive::ReadItem(int volIndex, int fsIndex, const CLongAllocDesc &la
|
||||
if (lad.GetLen() != vol.BlockSize)
|
||||
return S_FALSE;
|
||||
|
||||
size_t size = lad.GetLen();
|
||||
const size_t size = lad.GetLen();
|
||||
CByteBuffer buf(size);
|
||||
RINOK(Read(volIndex, lad, buf));
|
||||
|
||||
@@ -518,20 +518,20 @@ HRESULT CInArchive::ReadItem(int volIndex, int fsIndex, const CLongAllocDesc &la
|
||||
{
|
||||
if (!item.CheckChunkSizes() || !CheckItemExtents(volIndex, item))
|
||||
return S_FALSE;
|
||||
CByteBuffer buf;
|
||||
RINOK(ReadFromFile(volIndex, item, buf));
|
||||
CByteBuffer buf2;
|
||||
RINOK(ReadFromFile(volIndex, item, buf2));
|
||||
item.Size = 0;
|
||||
item.Extents.ClearAndFree();
|
||||
item.InlineData.Free();
|
||||
|
||||
const Byte *p = buf;
|
||||
size = buf.Size();
|
||||
const Byte *p2 = buf2;
|
||||
const size_t size2 = buf2.Size();
|
||||
size_t processedTotal = 0;
|
||||
for (; processedTotal < size;)
|
||||
for (; processedTotal < size2;)
|
||||
{
|
||||
size_t processedCur;
|
||||
CFileId fileId;
|
||||
RINOK(fileId.Parse(p + processedTotal, size - processedTotal, processedCur));
|
||||
RINOK(fileId.Parse(p2 + processedTotal, size2 - processedTotal, processedCur));
|
||||
if (!fileId.IsItLinkParent())
|
||||
{
|
||||
CFile file;
|
||||
@@ -599,8 +599,8 @@ API_FUNC_IsArc IsArc_Udf(const Byte *p, size_t size)
|
||||
{
|
||||
if (SecLogSize < 8)
|
||||
return res;
|
||||
UInt32 offset = (UInt32)256 << SecLogSize;
|
||||
size_t bufSize = (UInt32)1 << SecLogSize;
|
||||
const UInt32 offset = (UInt32)256 << SecLogSize;
|
||||
const UInt32 bufSize = (UInt32)1 << SecLogSize;
|
||||
if (offset + bufSize > size)
|
||||
res = k_IsArc_Res_NEED_MORE;
|
||||
else
|
||||
@@ -660,7 +660,7 @@ HRESULT CInArchive::Open2()
|
||||
if (offset >= fileSize)
|
||||
continue;
|
||||
RINOK(_stream->Seek(offset, STREAM_SEEK_SET, NULL));
|
||||
size_t bufSize = (UInt32)1 << SecLogSize;
|
||||
const size_t bufSize = (size_t)1 << SecLogSize;
|
||||
size_t readSize = bufSize;
|
||||
RINOK(ReadStream(_stream, buf, &readSize));
|
||||
if (readSize == bufSize)
|
||||
@@ -686,8 +686,7 @@ HRESULT CInArchive::Open2()
|
||||
|
||||
for (UInt32 location = 0; ; location++)
|
||||
{
|
||||
size_t bufSize = (UInt32)1 << SecLogSize;
|
||||
size_t pos = 0;
|
||||
const size_t bufSize = (size_t)1 << SecLogSize;
|
||||
if (((UInt64)(location + 1) << SecLogSize) > extentVDS.Len)
|
||||
return S_FALSE;
|
||||
|
||||
@@ -700,7 +699,10 @@ HRESULT CInArchive::Open2()
|
||||
|
||||
|
||||
CTag tag;
|
||||
RINOK(tag.Parse(buf + pos, bufSize - pos));
|
||||
{
|
||||
const size_t pos = 0;
|
||||
RINOK(tag.Parse(buf + pos, bufSize - pos));
|
||||
}
|
||||
if (tag.Id == DESC_TYPE_Terminating)
|
||||
break;
|
||||
|
||||
@@ -862,9 +864,9 @@ HRESULT CInArchive::Open2()
|
||||
{
|
||||
if (nextExtent.GetLen() < 512)
|
||||
return S_FALSE;
|
||||
CByteBuffer buf(nextExtent.GetLen());
|
||||
RINOK(Read(volIndex, nextExtent, buf));
|
||||
const Byte *p = buf;
|
||||
CByteBuffer buf2(nextExtent.GetLen());
|
||||
RINOK(Read(volIndex, nextExtent, buf2));
|
||||
const Byte *p = buf2;
|
||||
size_t size = nextExtent.GetLen();
|
||||
|
||||
CTag tag;
|
||||
|
||||
@@ -702,9 +702,10 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
int cur = item2.Parent;
|
||||
while (cur >= 0)
|
||||
{
|
||||
const CItem2 &item2 = _items2[cur];
|
||||
path = item2.Name + CHAR_PATH_SEPARATOR + path;
|
||||
cur = item2.Parent;
|
||||
const CItem2 &item3 = _items2[cur];
|
||||
path.InsertAtFront(CHAR_PATH_SEPARATOR);
|
||||
path.Insert(0, item3.Name);
|
||||
cur = item3.Parent;
|
||||
}
|
||||
prop = path;
|
||||
break;
|
||||
|
||||
@@ -532,9 +532,11 @@ STDMETHODIMP CHandler::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
*processedSize = 0;
|
||||
if (_virtPos >= Footer.CurrentSize)
|
||||
return S_OK;
|
||||
UInt64 rem = Footer.CurrentSize - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
{
|
||||
const UInt64 rem = Footer.CurrentSize - _virtPos;
|
||||
if (size > rem)
|
||||
size = (UInt32)rem;
|
||||
}
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
UInt32 blockIndex = (UInt32)(_virtPos >> Dyn.BlockSizeLog);
|
||||
@@ -565,7 +567,7 @@ STDMETHODIMP CHandler::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
RINOK(ReadPhy(newPos + BitMap.Size() + offsetInBlock, data, size));
|
||||
for (UInt32 cur = 0; cur < size;)
|
||||
{
|
||||
UInt32 rem = MyMin(0x200 - (offsetInBlock & 0x1FF), size - cur);
|
||||
const UInt32 rem = MyMin(0x200 - (offsetInBlock & 0x1FF), size - cur);
|
||||
UInt32 bmi = offsetInBlock >> kSectorSize_Log;
|
||||
if (((BitMap[bmi >> 3] >> (7 - (bmi & 7))) & 1) == 0)
|
||||
{
|
||||
|
||||
@@ -1349,43 +1349,45 @@ HRESULT CExtent::Open3(IInStream *stream, IArchiveOpenCallback *openCallback,
|
||||
|
||||
for (size_t i = 0; i < numGdeEntries; i++)
|
||||
{
|
||||
UInt32 v = Get32((const Byte *)table + (size_t)i * 4);
|
||||
CByteBuffer &buf = Tables.AddNew();
|
||||
if (v == 0 || v == ZeroSector)
|
||||
continue;
|
||||
if (openCallback && (i - numProcessed_Prev) >= 1024)
|
||||
{
|
||||
const UInt64 comp = complexityStart + ((UInt64)i << (k_NumMidBits + 2));
|
||||
const UInt64 volIndex2 = volIndex;
|
||||
RINOK(openCallback->SetCompleted(numVols == 1 ? NULL : &volIndex2, &comp));
|
||||
numProcessed_Prev = i;
|
||||
}
|
||||
|
||||
const size_t k_NumSectors = (size_t)1 << (k_NumMidBits - 9 + 2);
|
||||
|
||||
if (h.Is_Marker())
|
||||
{
|
||||
Byte buf2[1 << 9];
|
||||
if (ReadForHeader(stream, v - 1, buf2, 1) != S_OK)
|
||||
return S_FALSE;
|
||||
{
|
||||
CMarker m;
|
||||
m.Parse(buf2);
|
||||
if (m.Type != k_Marker_GRAIN_TABLE
|
||||
|| m.NumSectors != k_NumSectors
|
||||
|| m.SpecSize != 0)
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
const size_t k_NumMidItems = (size_t)1 << k_NumMidBits;
|
||||
|
||||
buf.Alloc(k_NumMidItems * 4);
|
||||
RINOK(ReadForHeader(stream, v, buf, k_NumSectors));
|
||||
CByteBuffer &buf = Tables.AddNew();
|
||||
|
||||
{
|
||||
const UInt32 v = Get32((const Byte *)table + (size_t)i * 4);
|
||||
if (v == 0 || v == ZeroSector)
|
||||
continue;
|
||||
if (openCallback && (i - numProcessed_Prev) >= 1024)
|
||||
{
|
||||
const UInt64 comp = complexityStart + ((UInt64)i << (k_NumMidBits + 2));
|
||||
const UInt64 volIndex2 = volIndex;
|
||||
RINOK(openCallback->SetCompleted(numVols == 1 ? NULL : &volIndex2, &comp));
|
||||
numProcessed_Prev = i;
|
||||
}
|
||||
|
||||
if (h.Is_Marker())
|
||||
{
|
||||
Byte buf2[1 << 9];
|
||||
if (ReadForHeader(stream, v - 1, buf2, 1) != S_OK)
|
||||
return S_FALSE;
|
||||
{
|
||||
CMarker m;
|
||||
m.Parse(buf2);
|
||||
if (m.Type != k_Marker_GRAIN_TABLE
|
||||
|| m.NumSectors != k_NumSectors
|
||||
|| m.SpecSize != 0)
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
buf.Alloc(k_NumMidItems * 4);
|
||||
RINOK(ReadForHeader(stream, v, buf, k_NumSectors));
|
||||
}
|
||||
|
||||
for (size_t k = 0; k < k_NumMidItems; k++)
|
||||
{
|
||||
UInt32 v = Get32((const Byte *)buf + (size_t)k * 4);
|
||||
const UInt32 v = Get32((const Byte *)buf + (size_t)k * 4);
|
||||
if (v == 0 || v == ZeroSector)
|
||||
continue;
|
||||
if (v < h.overHead)
|
||||
|
||||
@@ -130,9 +130,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
int index = -1;
|
||||
FOR_VECTOR (i, xml.Images)
|
||||
{
|
||||
const CImageInfo &image = xml.Images[i];
|
||||
if (image.CTimeDefined)
|
||||
if (index < 0 || ::CompareFileTime(&image.CTime, &xml.Images[index].CTime) < 0)
|
||||
const CImageInfo &image2 = xml.Images[i];
|
||||
if (image2.CTimeDefined)
|
||||
if (index < 0 || ::CompareFileTime(&image2.CTime, &xml.Images[index].CTime) < 0)
|
||||
index = i;
|
||||
}
|
||||
if (index >= 0)
|
||||
@@ -147,9 +147,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
int index = -1;
|
||||
FOR_VECTOR (i, xml.Images)
|
||||
{
|
||||
const CImageInfo &image = xml.Images[i];
|
||||
if (image.MTimeDefined)
|
||||
if (index < 0 || ::CompareFileTime(&image.MTime, &xml.Images[index].MTime) > 0)
|
||||
const CImageInfo &image2 = xml.Images[i];
|
||||
if (image2.MTimeDefined)
|
||||
if (index < 0 || ::CompareFileTime(&image2.MTime, &xml.Images[index].MTime) > 0)
|
||||
index = i;
|
||||
}
|
||||
if (index >= 0)
|
||||
@@ -158,7 +158,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
|
||||
break;
|
||||
|
||||
case kpidComment:
|
||||
if (image != NULL)
|
||||
if (image)
|
||||
{
|
||||
if (_xmlInComments)
|
||||
{
|
||||
|
||||
@@ -1351,9 +1351,11 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
|
||||
header.ChunkSizeBits = srcHeader.ChunkSizeBits;
|
||||
}
|
||||
|
||||
Byte buf[kHeaderSizeMax];
|
||||
header.WriteTo(buf);
|
||||
RINOK(WriteStream(outStream, buf, kHeaderSizeMax));
|
||||
{
|
||||
Byte buf[kHeaderSizeMax];
|
||||
header.WriteTo(buf);
|
||||
RINOK(WriteStream(outStream, buf, kHeaderSizeMax));
|
||||
}
|
||||
|
||||
UInt64 curPos = kHeaderSizeMax;
|
||||
|
||||
@@ -1754,14 +1756,14 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < secBufs.Size(); i++, pos += 8)
|
||||
unsigned k;
|
||||
for (k = 0; k < secBufs.Size(); k++, pos += 8)
|
||||
{
|
||||
Set64(meta + pos, secBufs[i].Size());
|
||||
Set64(meta + pos, secBufs[k].Size());
|
||||
}
|
||||
for (i = 0; i < secBufs.Size(); i++)
|
||||
for (k = 0; k < secBufs.Size(); k++)
|
||||
{
|
||||
const CByteBuffer &buf = secBufs[i];
|
||||
const CByteBuffer &buf = secBufs[k];
|
||||
size_t size = buf.Size();
|
||||
if (size != 0)
|
||||
{
|
||||
@@ -1888,8 +1890,11 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outSeqStream, UInt32 nu
|
||||
|
||||
outStream->Seek(0, STREAM_SEEK_SET, NULL);
|
||||
header.NumImages = trees.Size();
|
||||
header.WriteTo(buf);
|
||||
return WriteStream(outStream, buf, kHeaderSizeMax);
|
||||
{
|
||||
Byte buf[kHeaderSizeMax];
|
||||
header.WriteTo(buf);
|
||||
return WriteStream(outStream, buf, kHeaderSizeMax);
|
||||
}
|
||||
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
@@ -589,7 +589,7 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
|
||||
RINOK(OpenCallback->SetCompleted(&numFiles, NULL));
|
||||
}
|
||||
|
||||
size_t rem = DirSize - pos;
|
||||
const size_t rem = DirSize - pos;
|
||||
if (pos < DirStartOffset || pos > DirSize || rem < 8)
|
||||
return S_FALSE;
|
||||
|
||||
@@ -661,15 +661,15 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
|
||||
|
||||
for (UInt32 i = 0; i < numAltStreams; i++)
|
||||
{
|
||||
const size_t rem = DirSize - pos;
|
||||
if (pos < DirStartOffset || pos > DirSize || rem < 8)
|
||||
const size_t rem2 = DirSize - pos;
|
||||
if (pos < DirStartOffset || pos > DirSize || rem2 < 8)
|
||||
return S_FALSE;
|
||||
const Byte *p = DirData + pos;
|
||||
const UInt64 len = Get64(p);
|
||||
if ((len & align) != 0 || rem < len || len < (IsOldVersion ? 0x18 : 0x28))
|
||||
const Byte *p2 = DirData + pos;
|
||||
const UInt64 len2 = Get64(p2);
|
||||
if ((len2 & align) != 0 || rem2 < len2 || len2 < (IsOldVersion ? 0x18 : 0x28))
|
||||
return S_FALSE;
|
||||
|
||||
DirProcessed += (size_t)len;
|
||||
DirProcessed += (size_t)len2;
|
||||
if (DirProcessed > DirSize)
|
||||
return S_FALSE;
|
||||
|
||||
@@ -679,29 +679,29 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
|
||||
extraOffset = 0x10;
|
||||
else
|
||||
{
|
||||
if (Get64(p + 8) != 0)
|
||||
if (Get64(p2 + 8) != 0)
|
||||
return S_FALSE;
|
||||
extraOffset = 0x24;
|
||||
}
|
||||
|
||||
UInt32 fileNameLen = Get16(p + extraOffset);
|
||||
if ((fileNameLen & 1) != 0)
|
||||
const UInt32 fileNameLen111 = Get16(p2 + extraOffset);
|
||||
if ((fileNameLen111 & 1) != 0)
|
||||
return S_FALSE;
|
||||
/* Probably different versions of ImageX can use different number of
|
||||
additional ZEROs. So we don't use exact check. */
|
||||
UInt32 fileNameLen2 = (fileNameLen == 0 ? fileNameLen : fileNameLen + 2);
|
||||
if (((extraOffset + 2 + fileNameLen2 + align) & ~align) > len)
|
||||
const UInt32 fileNameLen222 = (fileNameLen111 == 0 ? fileNameLen111 : fileNameLen111 + 2);
|
||||
if (((extraOffset + 2 + fileNameLen222 + align) & ~align) > len2)
|
||||
return S_FALSE;
|
||||
|
||||
{
|
||||
const Byte *p2 = p + extraOffset + 2;
|
||||
if (*(const UInt16 *)(p2 + fileNameLen) != 0)
|
||||
const Byte *p3 = p2 + extraOffset + 2;
|
||||
if (*(const UInt16 *)(p3 + fileNameLen111) != 0)
|
||||
return S_FALSE;
|
||||
for (UInt32 j = 0; j < fileNameLen; j += 2)
|
||||
if (*(const UInt16 *)(p2 + j) == 0)
|
||||
for (UInt32 j = 0; j < fileNameLen111; j += 2)
|
||||
if (*(const UInt16 *)(p3 + j) == 0)
|
||||
return S_FALSE;
|
||||
|
||||
// PRF(printf("\n %S", p2));
|
||||
// PRF(printf("\n %S", p3));
|
||||
}
|
||||
|
||||
|
||||
@@ -712,16 +712,16 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
|
||||
|
||||
Byte *prevMeta = DirData + item.Offset;
|
||||
|
||||
if (fileNameLen == 0 &&
|
||||
if (fileNameLen111 == 0 &&
|
||||
((attrib & FILE_ATTRIBUTE_REPARSE_POINT) || !item.IsDir)
|
||||
&& (IsOldVersion || IsEmptySha(prevMeta + 0x40)))
|
||||
{
|
||||
if (IsOldVersion)
|
||||
memcpy(prevMeta + 0x10, p + 8, 4); // It's 32-bit Id
|
||||
else if (!IsEmptySha(p + 0x10))
|
||||
memcpy(prevMeta + 0x10, p2 + 8, 4); // It's 32-bit Id
|
||||
else if (!IsEmptySha(p2 + 0x10))
|
||||
{
|
||||
// if (IsEmptySha(prevMeta + 0x40))
|
||||
memcpy(prevMeta + 0x40, p + 0x10, kHashSize);
|
||||
memcpy(prevMeta + 0x40, p2 + 0x10, kHashSize);
|
||||
// else HeadersError = true;
|
||||
}
|
||||
}
|
||||
@@ -736,7 +736,7 @@ HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
|
||||
Items.Add(item2);
|
||||
}
|
||||
|
||||
pos += (size_t)len;
|
||||
pos += (size_t)len2;
|
||||
}
|
||||
|
||||
if (parent < 0 && numItems == 0 && shortNameLen == 0 && fileNameLen == 0 && item.IsDir)
|
||||
@@ -973,10 +973,15 @@ static HRESULT ReadStreams(IInStream *inStream, const CHeader &h, CDatabase &db)
|
||||
RINOK(unpacker.UnpackData(inStream, h.OffsetResource, h, NULL, offsetBuf, NULL));
|
||||
|
||||
const size_t streamInfoSize = h.IsOldVersion() ? kStreamInfoSize + 2 : kStreamInfoSize;
|
||||
unsigned numItems = (unsigned)(offsetBuf.Size() / streamInfoSize);
|
||||
if ((size_t)numItems * streamInfoSize != offsetBuf.Size())
|
||||
return S_FALSE;
|
||||
db.DataStreams.Reserve(numItems);
|
||||
{
|
||||
const unsigned numItems = (unsigned)(offsetBuf.Size() / streamInfoSize);
|
||||
if ((size_t)numItems * streamInfoSize != offsetBuf.Size())
|
||||
return S_FALSE;
|
||||
const unsigned numItems2 = db.DataStreams.Size() + numItems;
|
||||
if (numItems2 < numItems)
|
||||
return S_FALSE;
|
||||
db.DataStreams.Reserve(numItems2);
|
||||
}
|
||||
|
||||
bool keepSolid = false;
|
||||
|
||||
|
||||
@@ -486,14 +486,14 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
|
||||
int cur = index;
|
||||
do
|
||||
{
|
||||
const CFile &item = _files[cur];
|
||||
const CFile &item2 = _files[cur];
|
||||
if (!path.IsEmpty())
|
||||
path.InsertAtFront(CHAR_PATH_SEPARATOR);
|
||||
if (item.Name.IsEmpty())
|
||||
if (item2.Name.IsEmpty())
|
||||
path.Insert(0, "unknown");
|
||||
else
|
||||
path.Insert(0, item.Name);
|
||||
cur = item.Parent;
|
||||
path.Insert(0, item2.Name);
|
||||
cur = item2.Parent;
|
||||
}
|
||||
while (cur >= 0);
|
||||
|
||||
|
||||
@@ -297,11 +297,14 @@ HRESULT CInArchive::FindMarker(IInStream *stream, const UInt64 *searchLimit)
|
||||
if (searchLimit && *searchLimit == 0)
|
||||
{
|
||||
Byte startBuf[kMarkerSize];
|
||||
size_t processed = kMarkerSize;
|
||||
RINOK(ReadStream(stream, startBuf, &processed));
|
||||
m_Position += processed;
|
||||
if (processed < kMarkerSize)
|
||||
return S_FALSE;
|
||||
{
|
||||
size_t processed = kMarkerSize;
|
||||
RINOK(ReadStream(stream, startBuf, &processed));
|
||||
m_Position += processed;
|
||||
if (processed != kMarkerSize)
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
m_Signature = Get32(startBuf);
|
||||
|
||||
if (m_Signature != NSignature::kEcd &&
|
||||
@@ -318,7 +321,7 @@ HRESULT CInArchive::FindMarker(IInStream *stream, const UInt64 *searchLimit)
|
||||
size_t processed = kMarkerSize;
|
||||
RINOK(ReadStream(stream, startBuf, &processed));
|
||||
m_Position += processed;
|
||||
if (processed < kMarkerSize)
|
||||
if (processed != kMarkerSize)
|
||||
return S_FALSE;
|
||||
m_Signature = Get32(startBuf);
|
||||
if (m_Signature != NSignature::kEcd &&
|
||||
@@ -1567,7 +1570,7 @@ HRESULT CInArchive::ReadVols()
|
||||
if (Vols.StartIsZip)
|
||||
Vols.ZipStream = StartStream;
|
||||
|
||||
bool cdOK = false;
|
||||
// bool cdOK = false;
|
||||
|
||||
if (Vols.ZipStream)
|
||||
{
|
||||
@@ -1589,12 +1592,16 @@ HRESULT CInArchive::ReadVols()
|
||||
// Vols.EndVolIndex = ecd.ThisDisk;
|
||||
unsigned numMissingVols;
|
||||
if (cdDisk == zipDisk)
|
||||
cdOK = true;
|
||||
{
|
||||
// cdOK = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RINOK(ReadVols2(volCallback, cdDisk, zipDisk, zipDisk, 0, numMissingVols));
|
||||
if (numMissingVols == 0)
|
||||
cdOK = false;
|
||||
{
|
||||
// cdOK = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (res != S_FALSE)
|
||||
|
||||
@@ -596,6 +596,7 @@ static HRESULT Update2(
|
||||
UInt64 numBytesToCompress = 0;
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
{
|
||||
const CUpdateItem &ui = updateItems[i];
|
||||
@@ -731,7 +732,6 @@ static HRESULT Update2(
|
||||
for (i = 0; i < updateItems.Size(); i++)
|
||||
refs.Refs.Add(CMemBlocks2());
|
||||
|
||||
UInt32 i;
|
||||
for (i = 0; i < numThreads; i++)
|
||||
threads.Threads.Add(CThreadInfo(options2));
|
||||
|
||||
@@ -804,9 +804,9 @@ static HRESULT Update2(
|
||||
RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
|
||||
}
|
||||
|
||||
for (UInt32 i = 0; i < numThreads; i++)
|
||||
for (UInt32 k = 0; k < numThreads; k++)
|
||||
{
|
||||
CThreadInfo &threadInfo = threads.Threads[i];
|
||||
CThreadInfo &threadInfo = threads.Threads[k];
|
||||
if (threadInfo.IsFree)
|
||||
{
|
||||
threadInfo.IsFree = false;
|
||||
@@ -822,7 +822,7 @@ static HRESULT Update2(
|
||||
threadInfo.UpdateIndex = mtItemIndex - 1;
|
||||
|
||||
compressingCompletedEvents.Add(threadInfo.CompressionCompletedEvent);
|
||||
threadIndices.Add(i);
|
||||
threadIndices.Add(k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -927,10 +927,10 @@ static HRESULT Update2(
|
||||
}
|
||||
else
|
||||
{
|
||||
CMemBlocks2 &memRef = refs.Refs[threadInfo.UpdateIndex];
|
||||
threadInfo.OutStreamSpec->DetachData(memRef);
|
||||
memRef.CompressingResult = threadInfo.CompressingResult;
|
||||
memRef.Defined = true;
|
||||
CMemBlocks2 &memRef2 = refs.Refs[threadInfo.UpdateIndex];
|
||||
threadInfo.OutStreamSpec->DetachData(memRef2);
|
||||
memRef2.CompressingResult = threadInfo.CompressingResult;
|
||||
memRef2.Defined = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user