Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/Archive/Zip/ZipIn.cpp')
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipIn.cpp342
1 files changed, 186 insertions, 156 deletions
diff --git a/CPP/7zip/Archive/Zip/ZipIn.cpp b/CPP/7zip/Archive/Zip/ZipIn.cpp
index f8e81c59..d67713ce 100755
--- a/CPP/7zip/Archive/Zip/ZipIn.cpp
+++ b/CPP/7zip/Archive/Zip/ZipIn.cpp
@@ -9,18 +9,29 @@
#include "../../Common/LimitedStreams.h"
#include "../../Common/StreamUtils.h"
+extern "C"
+{
+ #include "../../../../C/CpuArch.h"
+}
+
+#define Get16(p) GetUi16(p)
+#define Get32(p) GetUi32(p)
+#define Get64(p) GetUi64(p)
+
namespace NArchive {
namespace NZip {
// static const char kEndOfString = '\0';
-
-bool CInArchive::Open(IInStream *inStream, const UInt64 *searchHeaderSizeLimit)
+
+HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
{
- m_Stream = inStream;
- if(m_Stream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition) != S_OK)
- return false;
+ Close();
+ RINOK(stream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));
m_Position = m_StreamStartPosition;
- return FindAndReadMarker(searchHeaderSizeLimit);
+ RINOK(FindAndReadMarker(stream, searchHeaderSizeLimit));
+ RINOK(stream->Seek(m_Position, STREAM_SEEK_SET, NULL));
+ m_Stream = stream;
+ return S_OK;
}
void CInArchive::Close()
@@ -38,85 +49,76 @@ HRESULT CInArchive::Seek(UInt64 offset)
static inline bool TestMarkerCandidate(const Byte *p, UInt32 &value)
{
- value = p[0] | (((UInt32)p[1]) << 8) | (((UInt32)p[2]) << 16) | (((UInt32)p[3]) << 24);
- return (value == NSignature::kLocalFileHeader) ||
+ value = Get32(p);
+ return
+ (value == NSignature::kLocalFileHeader) ||
(value == NSignature::kEndOfCentralDir);
}
static const UInt32 kNumMarkerAddtionalBytes = 2;
static inline bool TestMarkerCandidate2(const Byte *p, UInt32 &value)
{
- value = p[0] | (((UInt32)p[1]) << 8) | (((UInt32)p[2]) << 16) | (((UInt32)p[3]) << 24);
+ value = Get32(p);
if (value == NSignature::kEndOfCentralDir)
- {
- UInt16 nextWord = p[0] | (((UInt16)p[1]) << 8);
- return (nextWord == 0);
- }
- if (value != NSignature::kLocalFileHeader)
- return false;
- if (p[0] > 128)
- return false;
- return true;
+ return (Get16(p + 4) == 0);
+ return (value == NSignature::kLocalFileHeader && p[4] < 128);
}
-bool CInArchive::FindAndReadMarker(const UInt64 *searchHeaderSizeLimit)
+HRESULT CInArchive::FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
{
m_ArchiveInfo.Clear();
m_Position = m_StreamStartPosition;
- if(Seek(m_StreamStartPosition) != S_OK)
- return false;
Byte marker[NSignature::kMarkerSize];
- UInt32 processedSize;
- ReadBytes(marker, NSignature::kMarkerSize, &processedSize);
- if(processedSize != NSignature::kMarkerSize)
- return false;
+ RINOK(ReadStream_FALSE(stream, marker, NSignature::kMarkerSize));
+ m_Position += NSignature::kMarkerSize;
if (TestMarkerCandidate(marker, m_Signature))
- return true;
+ return S_OK;
CByteDynamicBuffer dynamicBuffer;
- static const UInt32 kSearchMarkerBufferSize = 0x10000;
+ const UInt32 kSearchMarkerBufferSize = 0x10000;
dynamicBuffer.EnsureCapacity(kSearchMarkerBufferSize);
Byte *buffer = dynamicBuffer;
UInt32 numBytesPrev = NSignature::kMarkerSize - 1;
- memmove(buffer, marker + 1, numBytesPrev);
+ memcpy(buffer, marker + 1, numBytesPrev);
UInt64 curTestPos = m_StreamStartPosition + 1;
for (;;)
{
if (searchHeaderSizeLimit != NULL)
if (curTestPos - m_StreamStartPosition > *searchHeaderSizeLimit)
break;
- UInt32 numReadBytes = kSearchMarkerBufferSize - numBytesPrev;
- ReadBytes(buffer + numBytesPrev, numReadBytes, &processedSize);
- UInt32 numBytesInBuffer = numBytesPrev + processedSize;
+ size_t numReadBytes = kSearchMarkerBufferSize - numBytesPrev;
+ RINOK(ReadStream(stream, buffer + numBytesPrev, &numReadBytes));
+ m_Position += numReadBytes;
+ UInt32 numBytesInBuffer = numBytesPrev + (UInt32)numReadBytes;
const UInt32 kMarker2Size = NSignature::kMarkerSize + kNumMarkerAddtionalBytes;
if (numBytesInBuffer < kMarker2Size)
break;
UInt32 numTests = numBytesInBuffer - kMarker2Size + 1;
- for(UInt32 pos = 0; pos < numTests; pos++, curTestPos++)
- {
+ for (UInt32 pos = 0; pos < numTests; pos++)
+ {
+ if (buffer[pos] != 0x50)
+ continue;
if (TestMarkerCandidate2(buffer + pos, m_Signature))
{
+ curTestPos += pos;
m_ArchiveInfo.StartPosition = curTestPos;
- // m_ArchiveInfo.Base = m_ArchiveInfo.StartPosition;
- // m_ArchiveInfo.Base = 0;
m_Position = curTestPos + NSignature::kMarkerSize;
- if(Seek(m_Position) != S_OK)
- return false;
- return true;
+ return S_OK;
}
}
+ curTestPos += numTests;
numBytesPrev = numBytesInBuffer - numTests;
memmove(buffer, buffer + numTests, numBytesPrev);
}
- return false;
+ return S_FALSE;
}
HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
{
size_t realProcessedSize = size;
HRESULT result = ReadStream(m_Stream, data, &realProcessedSize);
- if(processedSize != NULL)
+ if (processedSize != NULL)
*processedSize = (UInt32)realProcessedSize;
m_Position += realProcessedSize;
return result;
@@ -124,21 +126,21 @@ HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
void CInArchive::IncreaseRealPosition(UInt64 addValue)
{
- if(m_Stream->Seek(addValue, STREAM_SEEK_CUR, &m_Position) != S_OK)
+ if (m_Stream->Seek(addValue, STREAM_SEEK_CUR, &m_Position) != S_OK)
throw CInArchiveException(CInArchiveException::kSeekStreamError);
}
bool CInArchive::ReadBytesAndTestSize(void *data, UInt32 size)
{
UInt32 realProcessedSize;
- if(ReadBytes(data, size, &realProcessedSize) != S_OK)
+ if (ReadBytes(data, size, &realProcessedSize) != S_OK)
throw CInArchiveException(CInArchiveException::kReadStreamError);
return (realProcessedSize == size);
}
void CInArchive::SafeReadBytes(void *data, UInt32 size)
{
- if(!ReadBytesAndTestSize(data, size))
+ if (!ReadBytesAndTestSize(data, size))
throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
}
@@ -198,8 +200,10 @@ AString CInArchive::ReadFileName(UInt32 nameSize)
{
if (nameSize == 0)
return AString();
- SafeReadBytes(m_NameBuffer.GetBuffer(nameSize), nameSize);
- m_NameBuffer.ReleaseBuffer(nameSize);
+ char *p = m_NameBuffer.GetBuffer(nameSize);
+ SafeReadBytes(p, nameSize);
+ p[nameSize] = 0;
+ m_NameBuffer.ReleaseBuffer();
return m_NameBuffer;
}
@@ -217,7 +221,7 @@ void CInArchive::ThrowIncorrectArchiveException()
static UInt32 GetUInt32(const Byte *data)
{
- return
+ return
((UInt32)(Byte)data[0]) |
(((UInt32)(Byte)data[1]) << 8) |
(((UInt32)(Byte)data[2]) << 16) |
@@ -227,7 +231,7 @@ static UInt32 GetUInt32(const Byte *data)
/*
static UInt16 GetUInt16(const Byte *data)
{
- return
+ return
((UInt16)(Byte)data[0]) |
(((UInt16)(Byte)data[1]) << 8);
}
@@ -240,7 +244,7 @@ static UInt64 GetUInt64(const Byte *data)
-void CInArchive::ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock,
+void CInArchive::ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock,
UInt64 &unpackSize, UInt64 &packSize, UInt64 &localHeaderOffset, UInt32 &diskStartNumber)
{
extraBlock.Clear();
@@ -318,11 +322,11 @@ HRESULT CInArchive::ReadLocalItem(CItemEx &item)
{
UInt64 localHeaderOffset = 0;
UInt32 diskStartNumber = 0;
- ReadExtra(item.LocalExtraSize, item.LocalExtra, item.UnPackSize, item.PackSize,
+ ReadExtra(item.LocalExtraSize, item.LocalExtra, item.UnPackSize, item.PackSize,
localHeaderOffset, diskStartNumber);
}
/*
- if (item.IsDirectory())
+ if (item.IsDir())
item.UnPackSize = 0; // check It
*/
return S_OK;
@@ -354,10 +358,10 @@ HRESULT CInArchive::ReadLocalItemAfterCdItem(CItemEx &item)
if (item.CompressionMethod != localItem.CompressionMethod ||
// item.Time != localItem.Time ||
- (!localItem.HasDescriptor() &&
- (
+ (!localItem.HasDescriptor() &&
+ (
item.FileCRC != localItem.FileCRC ||
- item.PackSize != localItem.PackSize ||
+ item.PackSize != localItem.PackSize ||
item.UnPackSize != localItem.UnPackSize
)
) ||
@@ -394,7 +398,7 @@ HRESULT CInArchive::ReadLocalItemDescriptor(CItemEx &item)
UInt32 i;
for (i = 0; i <= numBytesInBuffer - NFileHeader::kDataDescriptorSize; i++)
{
- // descriptorSignature field is Info-ZIP's extension
+ // descriptorSignature field is Info-ZIP's extension
// to Zip specification.
UInt32 descriptorSignature = GetUInt32(buffer + i);
@@ -415,7 +419,7 @@ HRESULT CInArchive::ReadLocalItemDescriptor(CItemEx &item)
packedSize += i;
int j;
for (j = 0; i < numBytesInBuffer; i++, j++)
- buffer[j] = buffer[i];
+ buffer[j] = buffer[i];
numBytesInBuffer = j;
}
}
@@ -463,28 +467,31 @@ HRESULT CInArchive::ReadLocalItemAfterCdItemFull(CItemEx &item)
HRESULT CInArchive::ReadCdItem(CItemEx &item)
{
item.FromCentral = true;
- item.MadeByVersion.Version = ReadByte();
- item.MadeByVersion.HostOS = ReadByte();
- item.ExtractVersion.Version = ReadByte();
- item.ExtractVersion.HostOS = ReadByte();
- item.Flags = ReadUInt16();
- item.CompressionMethod = ReadUInt16();
- item.Time = ReadUInt32();
- item.FileCRC = ReadUInt32();
- item.PackSize = ReadUInt32();
- item.UnPackSize = ReadUInt32();
- UInt16 headerNameSize = ReadUInt16();
- UInt16 headerExtraSize = ReadUInt16();
- UInt16 headerCommentSize = ReadUInt16();
- UInt32 headerDiskNumberStart = ReadUInt16();
- item.InternalAttributes = ReadUInt16();
- item.ExternalAttributes = ReadUInt32();
- item.LocalHeaderPosition = ReadUInt32();
+ const int kBufSize = 42;
+ Byte p[kBufSize];
+ SafeReadBytes(p, kBufSize);
+ item.MadeByVersion.Version = p[0];
+ item.MadeByVersion.HostOS = p[1];
+ item.ExtractVersion.Version = p[2];
+ item.ExtractVersion.HostOS = p[3];
+ item.Flags = Get16(p + 4);
+ item.CompressionMethod = Get16(p + 6);
+ item.Time = Get32(p + 8);
+ item.FileCRC = Get32(p + 12);
+ item.PackSize = Get32(p + 16);
+ item.UnPackSize = Get32(p + 20);
+ UInt16 headerNameSize = Get16(p + 24);
+ UInt16 headerExtraSize = Get16(p + 26);
+ UInt16 headerCommentSize = Get16(p + 28);
+ UInt32 headerDiskNumberStart = Get16(p + 30);
+ item.InternalAttributes = Get16(p + 32);
+ item.ExternalAttributes = Get32(p + 34);
+ item.LocalHeaderPosition = Get32(p + 38);
item.Name = ReadFileName(headerNameSize);
if (headerExtraSize > 0)
{
- ReadExtra(headerExtraSize, item.CentralExtra, item.UnPackSize, item.PackSize,
+ ReadExtra(headerExtraSize, item.CentralExtra, item.UnPackSize, item.PackSize,
item.LocalHeaderPosition, headerDiskNumberStart);
}
@@ -493,7 +500,7 @@ HRESULT CInArchive::ReadCdItem(CItemEx &item)
// May be these strings must be deleted
/*
- if (item.IsDirectory())
+ if (item.IsDir())
item.UnPackSize = 0;
*/
@@ -506,7 +513,7 @@ HRESULT CInArchive::TryEcd64(UInt64 offset, CCdInfo &cdInfo)
RINOK(Seek(offset));
const UInt32 kEcd64Size = 56;
Byte buf[kEcd64Size];
- if(!ReadBytesAndTestSize(buf, kEcd64Size))
+ if (!ReadBytesAndTestSize(buf, kEcd64Size))
return S_FALSE;
if (GetUInt32(buf) != NSignature::kZip64EndOfCentralDir)
return S_FALSE;
@@ -531,7 +538,7 @@ HRESULT CInArchive::FindCd(CCdInfo &cdInfo)
return S_FALSE;
if (!ReadBytesAndTestSize(buf, bufSize))
return S_FALSE;
- for (int i = (int)(bufSize - kEcdSize); i >= 0; i--)
+ for (int i = (int)(bufSize - kEcdSize); i >= 0; i--)
{
if (GetUInt32(buf + i) == NSignature::kEndOfCentralDir)
{
@@ -566,7 +573,7 @@ HRESULT CInArchive::FindCd(CCdInfo &cdInfo)
return S_FALSE;
}
-HRESULT CInArchive::TryReadCd(CObjectVector<CItemEx> &items, UInt64 cdOffset, UInt64 cdSize)
+HRESULT CInArchive::TryReadCd(CObjectVector<CItemEx> &items, UInt64 cdOffset, UInt64 cdSize, CProgressVirt *progress)
{
items.Clear();
RINOK(m_Stream->Seek(cdOffset, STREAM_SEEK_SET, &m_Position));
@@ -574,16 +581,18 @@ HRESULT CInArchive::TryReadCd(CObjectVector<CItemEx> &items, UInt64 cdOffset, UI
return S_FALSE;
while(m_Position - cdOffset < cdSize)
{
- if(ReadUInt32() != NSignature::kCentralFileHeader)
+ if (ReadUInt32() != NSignature::kCentralFileHeader)
return S_FALSE;
CItemEx cdItem;
RINOK(ReadCdItem(cdItem));
items.Add(cdItem);
+ if (progress && items.Size() % 1000 == 0)
+ RINOK(progress->SetCompleted(items.Size()));
}
return (m_Position - cdOffset == cdSize) ? S_OK : S_FALSE;
}
-HRESULT CInArchive::ReadCd(CObjectVector<CItemEx> &items, UInt64 &cdOffset, UInt64 &cdSize)
+HRESULT CInArchive::ReadCd(CObjectVector<CItemEx> &items, UInt64 &cdOffset, UInt64 &cdSize, CProgressVirt *progress)
{
m_ArchiveInfo.Base = 0;
CCdInfo cdInfo;
@@ -591,10 +600,10 @@ HRESULT CInArchive::ReadCd(CObjectVector<CItemEx> &items, UInt64 &cdOffset, UInt
HRESULT res = S_FALSE;
cdSize = cdInfo.Size;
cdOffset = cdInfo.Offset;
- res = TryReadCd(items, m_ArchiveInfo.Base + cdOffset, cdSize);
+ res = TryReadCd(items, m_ArchiveInfo.Base + cdOffset, cdSize, progress);
if (res == S_FALSE && m_ArchiveInfo.Base == 0)
{
- res = TryReadCd(items, cdInfo.Offset + m_ArchiveInfo.StartPosition, cdSize);
+ res = TryReadCd(items, cdInfo.Offset + m_ArchiveInfo.StartPosition, cdSize, progress);
if (res == S_OK)
m_ArchiveInfo.Base = m_ArchiveInfo.StartPosition;
}
@@ -616,23 +625,17 @@ HRESULT CInArchive::ReadLocalsAndCd(CObjectVector<CItemEx> &items, CProgressVirt
item.FromLocal = true;
ReadLocalItemDescriptor(item);
items.Add(item);
- if (progress != 0)
- {
- UInt64 numItems = items.Size();
- RINOK(progress->SetCompleted(&numItems));
- }
+ if (progress && items.Size() % 100 == 0)
+ RINOK(progress->SetCompleted(items.Size()));
if (!ReadUInt32(m_Signature))
break;
}
cdOffset = m_Position - 4;
- for(int i = 0; i < items.Size(); i++)
+ for (int i = 0; i < items.Size(); i++)
{
- if (progress != 0)
- {
- UInt64 numItems = items.Size();
- RINOK(progress->SetCompleted(&numItems));
- }
- if(m_Signature != NSignature::kCentralFileHeader)
+ if (progress && i % 1000 == 0)
+ RINOK(progress->SetCompleted(items.Size()));
+ if (m_Signature != NSignature::kCentralFileHeader)
return S_FALSE;
CItemEx cdItem;
@@ -688,6 +691,58 @@ HRESULT CInArchive::ReadLocalsAndCd(CObjectVector<CItemEx> &items, CProgressVirt
return S_OK;
}
+struct CEcd
+{
+ UInt16 thisDiskNumber;
+ UInt16 startCDDiskNumber;
+ UInt16 numEntriesInCDOnThisDisk;
+ UInt16 numEntriesInCD;
+ UInt32 cdSize;
+ UInt32 cdStartOffset;
+ UInt16 commentSize;
+ void Parse(const Byte *p);
+};
+
+void CEcd::Parse(const Byte *p)
+{
+ thisDiskNumber = Get16(p);
+ startCDDiskNumber = Get16(p + 2);
+ numEntriesInCDOnThisDisk = Get16(p + 4);
+ numEntriesInCD = Get16(p + 6);
+ cdSize = Get32(p + 8);
+ cdStartOffset = Get32(p + 12);
+ commentSize = Get16(p + 16);
+}
+
+struct CEcd64
+{
+ UInt16 versionMade;
+ UInt16 versionNeedExtract;
+ UInt32 thisDiskNumber;
+ UInt32 startCDDiskNumber;
+ UInt64 numEntriesInCDOnThisDisk;
+ UInt64 numEntriesInCD;
+ UInt64 cdSize;
+ UInt64 cdStartOffset;
+ void Parse(const Byte *p);
+ CEcd64() { memset(this, 0, sizeof(*this)); }
+};
+
+void CEcd64::Parse(const Byte *p)
+{
+ versionMade = Get16(p);
+ versionNeedExtract = Get16(p + 2);
+ thisDiskNumber = Get32(p + 4);
+ startCDDiskNumber = Get32(p + 8);
+ numEntriesInCDOnThisDisk = Get64(p + 12);
+ numEntriesInCD = Get64(p + 20);
+ cdSize = Get64(p + 28);
+ cdStartOffset = Get64(p + 36);
+}
+
+#define COPY_ECD_ITEM_16(n) if (!isZip64 || ecd. ## n != 0xFFFF) ecd64. ## n = ecd. ## n;
+#define COPY_ECD_ITEM_32(n) if (!isZip64 || ecd. ## n != 0xFFFFFFFF) ecd64. ## n = ecd. ## n;
+
HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *progress)
{
// m_Signature must be kLocalFileHeaderSignature or
@@ -696,14 +751,9 @@ HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *pr
IsZip64 = false;
items.Clear();
- if (progress != 0)
- {
- UInt64 numItems = items.Size();
- RINOK(progress->SetCompleted(&numItems));
- }
UInt64 cdSize, cdStartOffset;
- HRESULT res = ReadCd(items, cdStartOffset, cdSize);
+ HRESULT res = ReadCd(items, cdStartOffset, cdSize, progress);
if (res != S_FALSE && res != S_OK)
return res;
@@ -726,39 +776,32 @@ HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *pr
cdStartOffset -= m_ArchiveInfo.Base;
}
- UInt32 thisDiskNumber = 0;
- UInt32 startCDDiskNumber = 0;
- UInt64 numEntriesInCDOnThisDisk = 0;
- UInt64 numEntriesInCD = 0;
- UInt64 cdSizeFromRecord = 0;
- UInt64 cdStartOffsetFromRecord = 0;
+ CEcd64 ecd64;
bool isZip64 = false;
UInt64 zip64EcdStartOffset = m_Position - 4 - m_ArchiveInfo.Base;
- if(m_Signature == NSignature::kZip64EndOfCentralDir)
+ if (m_Signature == NSignature::kZip64EndOfCentralDir)
{
IsZip64 = isZip64 = true;
UInt64 recordSize = ReadUInt64();
- /* UInt16 versionMade = */ ReadUInt16();
- /* UInt16 versionNeedExtract = */ ReadUInt16();
- thisDiskNumber = ReadUInt32();
- startCDDiskNumber = ReadUInt32();
- numEntriesInCDOnThisDisk = ReadUInt64();
- numEntriesInCD = ReadUInt64();
- cdSizeFromRecord = ReadUInt64();
- cdStartOffsetFromRecord = ReadUInt64();
+
+ const int kBufSize = kZip64EcdSize;
+ Byte buf[kBufSize];
+ SafeReadBytes(buf, kBufSize);
+ ecd64.Parse(buf);
+
IncreaseRealPosition(recordSize - kZip64EcdSize);
if (!ReadUInt32(m_Signature))
return S_FALSE;
- if (thisDiskNumber != 0 || startCDDiskNumber != 0)
+ if (ecd64.thisDiskNumber != 0 || ecd64.startCDDiskNumber != 0)
throw CInArchiveException(CInArchiveException::kMultiVolumeArchiveAreNotSupported);
- if (numEntriesInCDOnThisDisk != items.Size() ||
- numEntriesInCD != items.Size() ||
- cdSizeFromRecord != cdSize ||
- (cdStartOffsetFromRecord != cdStartOffset &&
+ if (ecd64.numEntriesInCDOnThisDisk != items.Size() ||
+ ecd64.numEntriesInCD != items.Size() ||
+ ecd64.cdSize != cdSize ||
+ (ecd64.cdStartOffset != cdStartOffset &&
(!items.IsEmpty())))
return S_FALSE;
}
- if(m_Signature == NSignature::kZip64EndOfCentralDirLocator)
+ if (m_Signature == NSignature::kZip64EndOfCentralDirLocator)
{
/* UInt32 startEndCDDiskNumber = */ ReadUInt32();
UInt64 endCDStartOffset = ReadUInt64();
@@ -768,42 +811,30 @@ HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *pr
if (!ReadUInt32(m_Signature))
return S_FALSE;
}
- if(m_Signature != NSignature::kEndOfCentralDir)
+ if (m_Signature != NSignature::kEndOfCentralDir)
return S_FALSE;
- UInt16 thisDiskNumber16 = ReadUInt16();
- if (!isZip64 || thisDiskNumber16 != 0xFFFF)
- thisDiskNumber = thisDiskNumber16;
-
- UInt16 startCDDiskNumber16 = ReadUInt16();
- if (!isZip64 || startCDDiskNumber16 != 0xFFFF)
- startCDDiskNumber = startCDDiskNumber16;
-
- UInt16 numEntriesInCDOnThisDisk16 = ReadUInt16();
- if (!isZip64 || numEntriesInCDOnThisDisk16 != 0xFFFF)
- numEntriesInCDOnThisDisk = numEntriesInCDOnThisDisk16;
+ const int kBufSize = kEcdSize - 4;
+ Byte buf[kBufSize];
+ SafeReadBytes(buf, kBufSize);
+ CEcd ecd;
+ ecd.Parse(buf);
- UInt16 numEntriesInCD16 = ReadUInt16();
- if (!isZip64 || numEntriesInCD16 != 0xFFFF)
- numEntriesInCD = numEntriesInCD16;
+ COPY_ECD_ITEM_16(thisDiskNumber);
+ COPY_ECD_ITEM_16(startCDDiskNumber);
+ COPY_ECD_ITEM_16(numEntriesInCDOnThisDisk);
+ COPY_ECD_ITEM_16(numEntriesInCD);
+ COPY_ECD_ITEM_32(cdSize);
+ COPY_ECD_ITEM_32(cdStartOffset);
- UInt32 cdSizeFromRecord32 = ReadUInt32();
- if (!isZip64 || cdSizeFromRecord32 != 0xFFFFFFFF)
- cdSizeFromRecord = cdSizeFromRecord32;
+ ReadBuffer(m_ArchiveInfo.Comment, ecd.commentSize);
- UInt32 cdStartOffsetFromRecord32 = ReadUInt32();
- if (!isZip64 || cdStartOffsetFromRecord32 != 0xFFFFFFFF)
- cdStartOffsetFromRecord = cdStartOffsetFromRecord32;
-
- UInt16 commentSize = ReadUInt16();
- ReadBuffer(m_ArchiveInfo.Comment, commentSize);
-
- if (thisDiskNumber != 0 || startCDDiskNumber != 0)
+ if (ecd64.thisDiskNumber != 0 || ecd64.startCDDiskNumber != 0)
throw CInArchiveException(CInArchiveException::kMultiVolumeArchiveAreNotSupported);
- if ((UInt16)numEntriesInCDOnThisDisk != ((UInt16)items.Size()) ||
- (UInt16)numEntriesInCD != ((UInt16)items.Size()) ||
- (UInt32)cdSizeFromRecord != (UInt32)cdSize ||
- ((UInt32)(cdStartOffsetFromRecord) != (UInt32)cdStartOffset &&
+ if ((UInt16)ecd64.numEntriesInCDOnThisDisk != ((UInt16)items.Size()) ||
+ (UInt16)ecd64.numEntriesInCD != ((UInt16)items.Size()) ||
+ (UInt32)ecd64.cdSize != (UInt32)cdSize ||
+ ((UInt32)(ecd64.cdStartOffset) != (UInt32)cdStartOffset &&
(!items.IsEmpty())))
return S_FALSE;
@@ -813,26 +844,25 @@ HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *pr
ISequentialInStream* CInArchive::CreateLimitedStream(UInt64 position, UInt64 size)
{
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
- CMyComPtr<ISequentialInStream> inStream(streamSpec);
+ CMyComPtr<ISequentialInStream> stream(streamSpec);
SeekInArchive(m_ArchiveInfo.Base + position);
streamSpec->SetStream(m_Stream);
streamSpec->Init(size);
- return inStream.Detach();
+ return stream.Detach();
}
IInStream* CInArchive::CreateStream()
{
- CMyComPtr<IInStream> inStream = m_Stream;
- return inStream.Detach();
+ CMyComPtr<IInStream> stream = m_Stream;
+ return stream.Detach();
}
bool CInArchive::SeekInArchive(UInt64 position)
{
UInt64 newPosition;
- if(m_Stream->Seek(position, STREAM_SEEK_SET, &newPosition) != S_OK)
+ if (m_Stream->Seek(position, STREAM_SEEK_SET, &newPosition) != S_OK)
return false;
return (newPosition == position);
}
}}
-