WimIn.cpp (p7zip_15.14.1_src_all) | : | WimIn.cpp (p7zip_16.02_src_all) | ||
---|---|---|---|---|
skipping to change at line 581 | skipping to change at line 581 | |||
return S_FALSE; | return S_FALSE; | |||
for (unsigned numItems = 0;; numItems++) | for (unsigned numItems = 0;; numItems++) | |||
{ | { | |||
if (OpenCallback && (Items.Size() & 0xFFFF) == 0) | if (OpenCallback && (Items.Size() & 0xFFFF) == 0) | |||
{ | { | |||
UInt64 numFiles = Items.Size(); | UInt64 numFiles = Items.Size(); | |||
RINOK(OpenCallback->SetCompleted(&numFiles, NULL)); | RINOK(OpenCallback->SetCompleted(&numFiles, NULL)); | |||
} | } | |||
size_t rem = DirSize - pos; | const size_t rem = DirSize - pos; | |||
if (pos < DirStartOffset || pos > DirSize || rem < 8) | if (pos < DirStartOffset || pos > DirSize || rem < 8) | |||
return S_FALSE; | return S_FALSE; | |||
const Byte *p = DirData + pos; | const Byte *p = DirData + pos; | |||
UInt64 len = Get64(p); | UInt64 len = Get64(p); | |||
if (len == 0) | if (len == 0) | |||
{ | { | |||
DirProcessed += 8; | DirProcessed += 8; | |||
return S_OK; | return S_OK; | |||
skipping to change at line 653 | skipping to change at line 653 | |||
item.Offset = pos; | item.Offset = pos; | |||
item.Parent = parent; | item.Parent = parent; | |||
item.ImageIndex = Images.Size() - 1; | item.ImageIndex = Images.Size() - 1; | |||
const unsigned prevIndex = Items.Add(item); | const unsigned prevIndex = Items.Add(item); | |||
pos += (size_t)len; | pos += (size_t)len; | |||
for (UInt32 i = 0; i < numAltStreams; i++) | for (UInt32 i = 0; i < numAltStreams; i++) | |||
{ | { | |||
const size_t rem = DirSize - pos; | const size_t rem2 = DirSize - pos; | |||
if (pos < DirStartOffset || pos > DirSize || rem < 8) | if (pos < DirStartOffset || pos > DirSize || rem2 < 8) | |||
return S_FALSE; | return S_FALSE; | |||
const Byte *p = DirData + pos; | const Byte *p2 = DirData + pos; | |||
const UInt64 len = Get64(p); | const UInt64 len2 = Get64(p2); | |||
if ((len & align) != 0 || rem < len || len < (IsOldVersion ? 0x18 : 0x28)) | if ((len2 & align) != 0 || rem2 < len2 || len2 < (IsOldVersion ? 0x18 : 0x | |||
28)) | ||||
return S_FALSE; | return S_FALSE; | |||
DirProcessed += (size_t)len; | DirProcessed += (size_t)len2; | |||
if (DirProcessed > DirSize) | if (DirProcessed > DirSize) | |||
return S_FALSE; | return S_FALSE; | |||
unsigned extraOffset = 0; | unsigned extraOffset = 0; | |||
if (IsOldVersion) | if (IsOldVersion) | |||
extraOffset = 0x10; | extraOffset = 0x10; | |||
else | else | |||
{ | { | |||
if (Get64(p + 8) != 0) | if (Get64(p2 + 8) != 0) | |||
return S_FALSE; | return S_FALSE; | |||
extraOffset = 0x24; | extraOffset = 0x24; | |||
} | } | |||
UInt32 fileNameLen = Get16(p + extraOffset); | const UInt32 fileNameLen111 = Get16(p2 + extraOffset); | |||
if ((fileNameLen & 1) != 0) | if ((fileNameLen111 & 1) != 0) | |||
return S_FALSE; | return S_FALSE; | |||
/* Probably different versions of ImageX can use different number of | /* Probably different versions of ImageX can use different number of | |||
additional ZEROs. So we don't use exact check. */ | additional ZEROs. So we don't use exact check. */ | |||
UInt32 fileNameLen2 = (fileNameLen == 0 ? fileNameLen : fileNameLen + 2); | const UInt32 fileNameLen222 = (fileNameLen111 == 0 ? fileNameLen111 : file | |||
if (((extraOffset + 2 + fileNameLen2 + align) & ~align) > len) | NameLen111 + 2); | |||
if (((extraOffset + 2 + fileNameLen222 + align) & ~align) > len2) | ||||
return S_FALSE; | return S_FALSE; | |||
{ | { | |||
const Byte *p2 = p + extraOffset + 2; | const Byte *p3 = p2 + extraOffset + 2; | |||
if (*(const UInt16 *)(p2 + fileNameLen) != 0) | if (*(const UInt16 *)(p3 + fileNameLen111) != 0) | |||
return S_FALSE; | return S_FALSE; | |||
for (UInt32 j = 0; j < fileNameLen; j += 2) | for (UInt32 j = 0; j < fileNameLen111; j += 2) | |||
if (*(const UInt16 *)(p2 + j) == 0) | if (*(const UInt16 *)(p3 + j) == 0) | |||
return S_FALSE; | return S_FALSE; | |||
// PRF(printf("\n %S", p2)); | // PRF(printf("\n %S", p3)); | |||
} | } | |||
/* wim uses alt sreams list, if there is at least one alt stream. | /* wim uses alt sreams list, if there is at least one alt stream. | |||
And alt stream without name is main stream. */ | And alt stream without name is main stream. */ | |||
// Why wimlib writes two alt streams for REPARSE_POINT, with empty second alt stream? | // Why wimlib writes two alt streams for REPARSE_POINT, with empty second alt stream? | |||
Byte *prevMeta = DirData + item.Offset; | Byte *prevMeta = DirData + item.Offset; | |||
if (fileNameLen == 0 && | if (fileNameLen111 == 0 && | |||
((attrib & FILE_ATTRIBUTE_REPARSE_POINT) || !item.IsDir) | ((attrib & FILE_ATTRIBUTE_REPARSE_POINT) || !item.IsDir) | |||
&& (IsOldVersion || IsEmptySha(prevMeta + 0x40))) | && (IsOldVersion || IsEmptySha(prevMeta + 0x40))) | |||
{ | { | |||
if (IsOldVersion) | if (IsOldVersion) | |||
memcpy(prevMeta + 0x10, p + 8, 4); // It's 32-bit Id | memcpy(prevMeta + 0x10, p2 + 8, 4); // It's 32-bit Id | |||
else if (!IsEmptySha(p + 0x10)) | else if (!IsEmptySha(p2 + 0x10)) | |||
{ | { | |||
// if (IsEmptySha(prevMeta + 0x40)) | // if (IsEmptySha(prevMeta + 0x40)) | |||
memcpy(prevMeta + 0x40, p + 0x10, kHashSize); | memcpy(prevMeta + 0x40, p2 + 0x10, kHashSize); | |||
// else HeadersError = true; | // else HeadersError = true; | |||
} | } | |||
} | } | |||
else | else | |||
{ | { | |||
ThereAreAltStreams = true; | ThereAreAltStreams = true; | |||
CItem item2; | CItem item2; | |||
item2.Offset = pos; | item2.Offset = pos; | |||
item2.IsAltStream = true; | item2.IsAltStream = true; | |||
item2.Parent = prevIndex; | item2.Parent = prevIndex; | |||
item2.ImageIndex = Images.Size() - 1; | item2.ImageIndex = Images.Size() - 1; | |||
Items.Add(item2); | Items.Add(item2); | |||
} | } | |||
pos += (size_t)len; | pos += (size_t)len2; | |||
} | } | |||
if (parent < 0 && numItems == 0 && shortNameLen == 0 && fileNameLen == 0 && item.IsDir) | if (parent < 0 && numItems == 0 && shortNameLen == 0 && fileNameLen == 0 && item.IsDir) | |||
{ | { | |||
const Byte *p2 = DirData + pos; | const Byte *p2 = DirData + pos; | |||
if (DirSize - pos >= 8 && Get64(p2) == 0) | if (DirSize - pos >= 8 && Get64(p2) == 0) | |||
{ | { | |||
CImage &image = Images.Back(); | CImage &image = Images.Back(); | |||
image.NumEmptyRootItems = 1; | image.NumEmptyRootItems = 1; | |||
skipping to change at line 960 | skipping to change at line 960 | |||
} | } | |||
static HRESULT ReadStreams(IInStream *inStream, const CHeader &h, CDatabase &db) | static HRESULT ReadStreams(IInStream *inStream, const CHeader &h, CDatabase &db) | |||
{ | { | |||
CByteBuffer offsetBuf; | CByteBuffer offsetBuf; | |||
CUnpacker unpacker; | CUnpacker unpacker; | |||
RINOK(unpacker.UnpackData(inStream, h.OffsetResource, h, NULL, offsetBuf, NULL )); | RINOK(unpacker.UnpackData(inStream, h.OffsetResource, h, NULL, offsetBuf, NULL )); | |||
const size_t streamInfoSize = h.IsOldVersion() ? kStreamInfoSize + 2 : kStream InfoSize; | const size_t streamInfoSize = h.IsOldVersion() ? kStreamInfoSize + 2 : kStream InfoSize; | |||
unsigned numItems = (unsigned)(offsetBuf.Size() / streamInfoSize); | { | |||
if ((size_t)numItems * streamInfoSize != offsetBuf.Size()) | const unsigned numItems = (unsigned)(offsetBuf.Size() / streamInfoSize); | |||
return S_FALSE; | if ((size_t)numItems * streamInfoSize != offsetBuf.Size()) | |||
db.DataStreams.Reserve(numItems); | return S_FALSE; | |||
const unsigned numItems2 = db.DataStreams.Size() + numItems; | ||||
if (numItems2 < numItems) | ||||
return S_FALSE; | ||||
db.DataStreams.Reserve(numItems2); | ||||
} | ||||
bool keepSolid = false; | bool keepSolid = false; | |||
for (size_t i = 0; i < offsetBuf.Size(); i += streamInfoSize) | for (size_t i = 0; i < offsetBuf.Size(); i += streamInfoSize) | |||
{ | { | |||
CStreamInfo s; | CStreamInfo s; | |||
ParseStream(h.IsOldVersion(), (const Byte *)offsetBuf + i, s); | ParseStream(h.IsOldVersion(), (const Byte *)offsetBuf + i, s); | |||
PRF(printf("\n")); | PRF(printf("\n")); | |||
PRF(printf(s.Resource.IsMetadata() ? "### META" : " DATA")); | PRF(printf(s.Resource.IsMetadata() ? "### META" : " DATA")); | |||
End of changes. 15 change blocks. | ||||
26 lines changed or deleted | 33 lines changed or added |