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')
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipAddCommon.cpp3
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipHandler.cpp160
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipHeader.h15
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipIn.cpp175
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipIn.h12
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipItem.cpp25
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipItem.h12
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipRegister.cpp2
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipUpdate.cpp3
9 files changed, 220 insertions, 187 deletions
diff --git a/CPP/7zip/Archive/Zip/ZipAddCommon.cpp b/CPP/7zip/Archive/Zip/ZipAddCommon.cpp
index 212a8b4b..9157deeb 100755
--- a/CPP/7zip/Archive/Zip/ZipAddCommon.cpp
+++ b/CPP/7zip/Archive/Zip/ZipAddCommon.cpp
@@ -2,10 +2,7 @@
#include "StdAfx.h"
-extern "C"
-{
#include "../../../../C/7zCrc.h"
-}
#include "Windows/PropVariant.h"
diff --git a/CPP/7zip/Archive/Zip/ZipHandler.cpp b/CPP/7zip/Archive/Zip/ZipHandler.cpp
index 25cbd886..547ecf92 100755
--- a/CPP/7zip/Archive/Zip/ZipHandler.cpp
+++ b/CPP/7zip/Archive/Zip/ZipHandler.cpp
@@ -3,16 +3,13 @@
#include "StdAfx.h"
#include "Common/ComTry.h"
-#include "Common/Defs.h"
#include "Common/IntToString.h"
-#include "Common/StringConvert.h"
#include "Windows/PropVariant.h"
#include "Windows/Time.h"
#include "../../IPassword.h"
-#include "../../Common/CreateCoder.h"
#include "../../Common/FilterCoder.h"
#include "../../Common/ProgressUtils.h"
#include "../../Common/StreamObjects.h"
@@ -37,38 +34,34 @@ using namespace NWindows;
namespace NArchive {
namespace NZip {
-// static const CMethodId kMethodId_Store = 0;
static const CMethodId kMethodId_ZipBase = 0x040100;
static const CMethodId kMethodId_BZip2 = 0x040202;
-const wchar_t *kHostOS[] =
+static const char *kHostOS[] =
{
- L"FAT",
- L"AMIGA",
- L"VMS",
- L"Unix",
- L"VM/CMS",
- L"Atari",
- L"HPFS",
- L"Macintosh",
- L"Z-System",
- L"CP/M",
- L"TOPS-20",
- L"NTFS",
- L"SMS/QDOS",
- L"Acorn",
- L"VFAT",
- L"MVS",
- L"BeOS",
- L"Tandem",
- L"OS/400",
- L"OS/X"
+ "FAT",
+ "AMIGA",
+ "VMS",
+ "Unix",
+ "VM/CMS",
+ "Atari",
+ "HPFS",
+ "Macintosh",
+ "Z-System",
+ "CP/M",
+ "TOPS-20",
+ "NTFS",
+ "SMS/QDOS",
+ "Acorn",
+ "VFAT",
+ "MVS",
+ "BeOS",
+ "Tandem",
+ "OS/400",
+ "OS/X"
};
-
-static const int kNumHostOSes = sizeof(kHostOS) / sizeof(kHostOS[0]);
-
-static const wchar_t *kUnknownOS = L"Unknown";
+static const char *kUnknownOS = "Unknown";
STATPROPSTG kProps[] =
{
@@ -93,50 +86,50 @@ STATPROPSTG kProps[] =
// { NULL, kpidUnpackVer, VT_UI1},
};
-const wchar_t *kMethods[] =
+const char *kMethods[] =
{
- L"Store",
- L"Shrink",
- L"Reduced1",
- L"Reduced2",
- L"Reduced2",
- L"Reduced3",
- L"Implode",
- L"Tokenizing",
- L"Deflate",
- L"Deflate64",
- L"PKImploding"
+ "Store",
+ "Shrink",
+ "Reduced1",
+ "Reduced2",
+ "Reduced2",
+ "Reduced3",
+ "Implode",
+ "Tokenizing",
+ "Deflate",
+ "Deflate64",
+ "PKImploding"
};
const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]);
-const wchar_t *kBZip2Method = L"BZip2";
-const wchar_t *kLZMAMethod = L"LZMA";
-const wchar_t *kJpegMethod = L"Jpeg";
-const wchar_t *kWavPackMethod = L"WavPack";
-const wchar_t *kPPMdMethod = L"PPMd";
-const wchar_t *kAESMethod = L"AES";
-const wchar_t *kZipCryptoMethod = L"ZipCrypto";
-const wchar_t *kStrongCryptoMethod = L"StrongCrypto";
+const char *kBZip2Method = "BZip2";
+const char *kLZMAMethod = "LZMA";
+const char *kJpegMethod = "Jpeg";
+const char *kWavPackMethod = "WavPack";
+const char *kPPMdMethod = "PPMd";
+const char *kAESMethod = "AES";
+const char *kZipCryptoMethod = "ZipCrypto";
+const char *kStrongCryptoMethod = "StrongCrypto";
struct CStrongCryptoPair
{
UInt16 Id;
- const wchar_t *Name;
+ const char *Name;
};
CStrongCryptoPair g_StrongCryptoPairs[] =
{
- { NStrongCryptoFlags::kDES, L"DES" },
- { NStrongCryptoFlags::kRC2old, L"RC2a" },
- { NStrongCryptoFlags::k3DES168, L"3DES-168" },
- { NStrongCryptoFlags::k3DES112, L"3DES-112" },
- { NStrongCryptoFlags::kAES128, L"pkAES-128" },
- { NStrongCryptoFlags::kAES192, L"pkAES-192" },
- { NStrongCryptoFlags::kAES256, L"pkAES-256" },
- { NStrongCryptoFlags::kRC2, L"RC2" },
- { NStrongCryptoFlags::kBlowfish, L"Blowfish" },
- { NStrongCryptoFlags::kTwofish, L"Twofish" },
- { NStrongCryptoFlags::kRC4, L"RC4" }
+ { NStrongCryptoFlags::kDES, "DES" },
+ { NStrongCryptoFlags::kRC2old, "RC2a" },
+ { NStrongCryptoFlags::k3DES168, "3DES-168" },
+ { NStrongCryptoFlags::k3DES112, "3DES-112" },
+ { NStrongCryptoFlags::kAES128, "pkAES-128" },
+ { NStrongCryptoFlags::kAES192, "pkAES-192" },
+ { NStrongCryptoFlags::kAES256, "pkAES-256" },
+ { NStrongCryptoFlags::kRC2, "RC2" },
+ { NStrongCryptoFlags::kBlowfish, "Blowfish" },
+ { NStrongCryptoFlags::kTwofish, "Twofish" },
+ { NStrongCryptoFlags::kRC4, "RC4" }
};
STATPROPSTG kArcProps[] =
@@ -202,9 +195,14 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
case kpidPackSize: prop = item.PackSize; break;
case kpidTimeType:
{
- FILETIME utcFileTime;
- if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kTagTime, utcFileTime))
+ FILETIME ft;
+ UInt32 unixTime;
+ if (item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kMTime, ft))
prop = (UInt32)NFileTimeType::kWindows;
+ else if (item.CentralExtra.GetUnixTime(NFileHeader::NUnixTime::kMTime, unixTime))
+ prop = (UInt32)NFileTimeType::kUnix;
+ else
+ prop = (UInt32)NFileTimeType::kDOS;
break;
}
case kpidCTime:
@@ -223,19 +221,21 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
}
case kpidMTime:
{
- FILETIME utcFileTime;
- if (!item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kMTime, utcFileTime))
+ FILETIME utc;
+ if (!item.CentralExtra.GetNtfsTime(NFileHeader::NNtfsExtra::kMTime, utc))
{
- FILETIME localFileTime;
- if (NTime::DosTimeToFileTime(item.Time, localFileTime))
+ UInt32 unixTime;
+ if (item.CentralExtra.GetUnixTime(NFileHeader::NUnixTime::kMTime, unixTime))
+ NTime::UnixTimeToFileTime(unixTime, utc);
+ else
{
- if (!LocalFileTimeToFileTime(&localFileTime, &utcFileTime))
- utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
+ FILETIME localFileTime;
+ if (!NTime::DosTimeToFileTime(item.Time, localFileTime) ||
+ !LocalFileTimeToFileTime(&localFileTime, &utc))
+ utc.dwHighDateTime = utc.dwLowDateTime = 0;
}
- else
- utcFileTime.dwHighDateTime = utcFileTime.dwLowDateTime = 0;
}
- prop = utcFileTime;
+ prop = utc;
break;
}
case kpidAttrib: prop = item.GetWinAttributes(); break;
@@ -245,7 +245,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
case kpidMethod:
{
UInt16 methodId = item.CompressionMethod;
- UString method;
+ AString method;
if (item.IsEncrypted())
{
if (methodId == NFileHeader::NCompressionMethod::kWzAES)
@@ -254,11 +254,11 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
CWzAesExtraField aesField;
if (item.CentralExtra.GetWzAesField(aesField))
{
- method += L"-";
- wchar_t s[32];
+ method += '-';
+ char s[32];
ConvertUInt64ToString((aesField.Strength + 1) * 64 , s);
method += s;
- method += L" ";
+ method += ' ';
methodId = aesField.Method;
}
}
@@ -286,7 +286,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
}
else
method += kZipCryptoMethod;
- method += L" ";
+ method += ' ';
}
}
if (methodId < kNumMethods)
@@ -296,7 +296,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
case NFileHeader::NCompressionMethod::kLZMA:
method += kLZMAMethod;
if (item.IsLzmaEOS())
- method += L":EOS";
+ method += ":EOS";
break;
case NFileHeader::NCompressionMethod::kBZip2: method += kBZip2Method; break;
case NFileHeader::NCompressionMethod::kJpeg: method += kJpegMethod; break;
@@ -304,7 +304,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
case NFileHeader::NCompressionMethod::kPPMd: method += kPPMdMethod; break;
default:
{
- wchar_t s[32];
+ char s[32];
ConvertUInt64ToString(methodId, s);
method += s;
}
@@ -313,7 +313,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
break;
}
case kpidHostOS:
- prop = (item.MadeByVersion.HostOS < kNumHostOSes) ?
+ prop = (item.MadeByVersion.HostOS < sizeof(kHostOS) / sizeof(kHostOS[0])) ?
(kHostOS[item.MadeByVersion.HostOS]) : kUnknownOS;
break;
}
diff --git a/CPP/7zip/Archive/Zip/ZipHeader.h b/CPP/7zip/Archive/Zip/ZipHeader.h
index e974079d..4839f554 100755
--- a/CPP/7zip/Archive/Zip/ZipHeader.h
+++ b/CPP/7zip/Archive/Zip/ZipHeader.h
@@ -93,6 +93,7 @@ namespace NFileHeader
kZip64 = 0x01,
kNTFS = 0x0A,
kStrongEncrypt = 0x17,
+ kUnixTime = 0x5455,
kWzAES = 0x9901
};
}
@@ -103,8 +104,18 @@ namespace NFileHeader
enum
{
kMTime = 0,
- kATime = 1,
- kCTime = 2
+ kATime,
+ kCTime
+ };
+ }
+
+ namespace NUnixTime
+ {
+ enum
+ {
+ kMTime = 0,
+ kATime,
+ kCTime
};
}
diff --git a/CPP/7zip/Archive/Zip/ZipIn.cpp b/CPP/7zip/Archive/Zip/ZipIn.cpp
index 5fb53ef2..e396fe5b 100755
--- a/CPP/7zip/Archive/Zip/ZipIn.cpp
+++ b/CPP/7zip/Archive/Zip/ZipIn.cpp
@@ -2,17 +2,14 @@
#include "StdAfx.h"
-#include "ZipIn.h"
-#include "Windows/Defs.h"
-#include "Common/StringConvert.h"
+#include "../../../../C/CpuArch.h"
+
#include "Common/DynamicBuffer.h"
+
#include "../../Common/LimitedStreams.h"
#include "../../Common/StreamUtils.h"
-extern "C"
-{
- #include "../../../../C/CpuArch.h"
-}
+#include "ZipIn.h"
#define Get16(p) GetUi16(p)
#define Get32(p) GetUi32(p)
@@ -21,10 +18,9 @@ extern "C"
namespace NArchive {
namespace NZip {
-// static const char kEndOfString = '\0';
-
HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
{
+ _inBufMode = false;
Close();
RINOK(stream->Seek(0, STREAM_SEEK_CUR, &m_StreamStartPosition));
m_Position = m_StreamStartPosition;
@@ -36,6 +32,7 @@ HRESULT CInArchive::Open(IInStream *stream, const UInt64 *searchHeaderSizeLimit)
void CInArchive::Close()
{
+ _inBuffer.ReleaseStream();
m_Stream.Release();
}
@@ -117,13 +114,26 @@ HRESULT CInArchive::FindAndReadMarker(IInStream *stream, const UInt64 *searchHea
HRESULT CInArchive::ReadBytes(void *data, UInt32 size, UInt32 *processedSize)
{
size_t realProcessedSize = size;
- HRESULT result = ReadStream(m_Stream, data, &realProcessedSize);
+ HRESULT result = S_OK;
+ if (_inBufMode)
+ {
+ try { realProcessedSize = _inBuffer.ReadBytes((Byte *)data, size); }
+ catch (const CInBufferException &e) { return e.ErrorCode; }
+ }
+ else
+ result = ReadStream(m_Stream, data, &realProcessedSize);
if (processedSize != NULL)
*processedSize = (UInt32)realProcessedSize;
m_Position += realProcessedSize;
return result;
}
+void CInArchive::Skip(UInt64 num)
+{
+ for (UInt64 i = 0; i < num; i++)
+ ReadByte();
+}
+
void CInArchive::IncreaseRealPosition(UInt64 addValue)
{
if (m_Stream->Seek(addValue, STREAM_SEEK_CUR, &m_Position) != S_OK)
@@ -160,51 +170,42 @@ Byte CInArchive::ReadByte()
UInt16 CInArchive::ReadUInt16()
{
- UInt16 value = 0;
- for (int i = 0; i < 2; i++)
- value |= (((UInt16)ReadByte()) << (8 * i));
- return value;
+ Byte buf[2];
+ SafeReadBytes(buf, 2);
+ return Get16(buf);
}
UInt32 CInArchive::ReadUInt32()
{
- UInt32 value = 0;
- for (int i = 0; i < 4; i++)
- value |= (((UInt32)ReadByte()) << (8 * i));
- return value;
+ Byte buf[4];
+ SafeReadBytes(buf, 4);
+ return Get32(buf);
}
UInt64 CInArchive::ReadUInt64()
{
- UInt64 value = 0;
- for (int i = 0; i < 8; i++)
- value |= (((UInt64)ReadByte()) << (8 * i));
- return value;
+ Byte buf[8];
+ SafeReadBytes(buf, 8);
+ return Get64(buf);
}
bool CInArchive::ReadUInt32(UInt32 &value)
{
- value = 0;
- for (int i = 0; i < 4; i++)
- {
- Byte b;
- if (!ReadBytesAndTestSize(&b, 1))
- return false;
- value |= (UInt32(b) << (8 * i));
- }
+ Byte buf[4];
+ if (!ReadBytesAndTestSize(buf, 4))
+ return false;
+ value = Get32(buf);
return true;
}
-
-AString CInArchive::ReadFileName(UInt32 nameSize)
+void CInArchive::ReadFileName(UInt32 nameSize, AString &dest)
{
if (nameSize == 0)
- return AString();
- char *p = m_NameBuffer.GetBuffer(nameSize);
+ dest.Empty();
+ char *p = dest.GetBuffer((int)nameSize);
SafeReadBytes(p, nameSize);
p[nameSize] = 0;
- m_NameBuffer.ReleaseBuffer();
- return m_NameBuffer;
+ dest.ReleaseBuffer();
}
void CInArchive::GetArchiveInfo(CInArchiveInfo &archiveInfo) const
@@ -212,38 +213,6 @@ void CInArchive::GetArchiveInfo(CInArchiveInfo &archiveInfo) const
archiveInfo = m_ArchiveInfo;
}
-/*
-void CInArchive::ThrowIncorrectArchiveException()
-{
- throw CInArchiveException(CInArchiveException::kIncorrectArchive);
-}
-*/
-
-static UInt32 GetUInt32(const Byte *data)
-{
- return
- ((UInt32)(Byte)data[0]) |
- (((UInt32)(Byte)data[1]) << 8) |
- (((UInt32)(Byte)data[2]) << 16) |
- (((UInt32)(Byte)data[3]) << 24);
-}
-
-/*
-static UInt16 GetUInt16(const Byte *data)
-{
- return
- ((UInt16)(Byte)data[0]) |
- (((UInt16)(Byte)data[1]) << 8);
-}
-*/
-
-static UInt64 GetUInt64(const Byte *data)
-{
- return GetUInt32(data) | ((UInt64)GetUInt32(data + 4) << 32);
-}
-
-
-
void CInArchive::ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock,
UInt64 &unpackSize, UInt64 &packSize, UInt64 &localHeaderOffset, UInt32 &diskStartNumber)
{
@@ -301,22 +270,26 @@ void CInArchive::ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock,
}
remain -= dataSize;
}
- IncreaseRealPosition(remain);
+ Skip(remain);
}
HRESULT CInArchive::ReadLocalItem(CItemEx &item)
{
- 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();
- UInt32 fileNameSize = ReadUInt16();
- item.LocalExtraSize = ReadUInt16();
- item.Name = ReadFileName(fileNameSize);
+ const int kBufSize = 26;
+ Byte p[kBufSize];
+ SafeReadBytes(p, kBufSize);
+
+ item.ExtractVersion.Version = p[0];
+ item.ExtractVersion.HostOS = p[1];
+ item.Flags = Get16(p + 2);
+ item.CompressionMethod = Get16(p + 4);
+ item.Time = Get32(p + 6);
+ item.FileCRC = Get32(p + 10);
+ item.PackSize = Get32(p + 14);
+ item.UnPackSize = Get32(p + 18);
+ UInt32 fileNameSize = Get16(p + 22);
+ item.LocalExtraSize = Get16(p + 24);
+ ReadFileName(fileNameSize, item.Name);
item.FileHeaderWithNameSize = 4 + NFileHeader::kLocalBlockSize + fileNameSize;
if (item.LocalExtraSize > 0)
{
@@ -400,16 +373,16 @@ HRESULT CInArchive::ReadLocalItemDescriptor(CItemEx &item)
{
// descriptorSignature field is Info-ZIP's extension
// to Zip specification.
- UInt32 descriptorSignature = GetUInt32(buffer + i);
+ UInt32 descriptorSignature = Get32(buffer + i);
// !!!! It must be fixed for Zip64 archives
- UInt32 descriptorPackSize = GetUInt32(buffer + i + 8);
+ UInt32 descriptorPackSize = Get32(buffer + i + 8);
if (descriptorSignature== NSignature::kDataDescriptor && descriptorPackSize == packedSize + i)
{
descriptorWasFound = true;
- item.FileCRC = GetUInt32(buffer + i + 4);
+ item.FileCRC = Get32(buffer + i + 4);
item.PackSize = descriptorPackSize;
- item.UnPackSize = GetUInt32(buffer + i + 12);
+ item.UnPackSize = Get32(buffer + i + 12);
IncreaseRealPosition(Int64(Int32(0 - (numBytesInBuffer - i - NFileHeader::kDataDescriptorSize))));
break;
}
@@ -487,7 +460,7 @@ HRESULT CInArchive::ReadCdItem(CItemEx &item)
item.InternalAttributes = Get16(p + 32);
item.ExternalAttributes = Get32(p + 34);
item.LocalHeaderPosition = Get32(p + 38);
- item.Name = ReadFileName(headerNameSize);
+ ReadFileName(headerNameSize, item.Name);
if (headerExtraSize > 0)
{
@@ -515,11 +488,11 @@ HRESULT CInArchive::TryEcd64(UInt64 offset, CCdInfo &cdInfo)
Byte buf[kEcd64Size];
if (!ReadBytesAndTestSize(buf, kEcd64Size))
return S_FALSE;
- if (GetUInt32(buf) != NSignature::kZip64EndOfCentralDir)
+ if (Get32(buf) != NSignature::kZip64EndOfCentralDir)
return S_FALSE;
- // cdInfo.NumEntries = GetUInt64(buf + 24);
- cdInfo.Size = GetUInt64(buf + 40);
- cdInfo.Offset = GetUInt64(buf + 48);
+ // cdInfo.NumEntries = Get64(buf + 24);
+ cdInfo.Size = Get64(buf + 40);
+ cdInfo.Offset = Get64(buf + 48);
return S_OK;
}
@@ -540,14 +513,14 @@ HRESULT CInArchive::FindCd(CCdInfo &cdInfo)
return S_FALSE;
for (int i = (int)(bufSize - kEcdSize); i >= 0; i--)
{
- if (GetUInt32(buf + i) == NSignature::kEndOfCentralDir)
+ if (Get32(buf + i) == NSignature::kEndOfCentralDir)
{
if (i >= kZip64EcdLocatorSize)
{
const Byte *locator = buf + i - kZip64EcdLocatorSize;
- if (GetUInt32(locator) == NSignature::kZip64EndOfCentralDirLocator)
+ if (Get32(locator) == NSignature::kZip64EndOfCentralDirLocator)
{
- UInt64 ecd64Offset = GetUInt64(locator + 8);
+ UInt64 ecd64Offset = Get64(locator + 8);
if (TryEcd64(ecd64Offset, cdInfo) == S_OK)
return S_OK;
if (TryEcd64(m_ArchiveInfo.StartPosition + ecd64Offset, cdInfo) == S_OK)
@@ -557,11 +530,11 @@ HRESULT CInArchive::FindCd(CCdInfo &cdInfo)
}
}
}
- if (GetUInt32(buf + i + 4) == 0)
+ if (Get32(buf + i + 4) == 0)
{
// cdInfo.NumEntries = GetUInt16(buf + i + 10);
- cdInfo.Size = GetUInt32(buf + i + 12);
- cdInfo.Offset = GetUInt32(buf + i + 16);
+ cdInfo.Size = Get32(buf + i + 12);
+ cdInfo.Offset = Get32(buf + i + 16);
UInt64 curPos = endPosition - bufSize + i;
UInt64 cdEnd = cdInfo.Size + cdInfo.Offset;
if (curPos > cdEnd)
@@ -579,6 +552,13 @@ HRESULT CInArchive::TryReadCd(CObjectVector<CItemEx> &items, UInt64 cdOffset, UI
RINOK(m_Stream->Seek(cdOffset, STREAM_SEEK_SET, &m_Position));
if (m_Position != cdOffset)
return S_FALSE;
+
+ if (!_inBuffer.Create(1 << 15))
+ return E_OUTOFMEMORY;
+ _inBuffer.SetStream(m_Stream);
+ _inBuffer.Init();
+ _inBufMode = true;
+
while(m_Position - cdOffset < cdSize)
{
if (ReadUInt32() != NSignature::kCentralFileHeader)
@@ -765,6 +745,7 @@ HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *pr
if (res == S_FALSE)
{
+ _inBufMode = false;
m_ArchiveInfo.Base = 0;
RINOK(m_Stream->Seek(m_ArchiveInfo.StartPosition, STREAM_SEEK_SET, &m_Position));
if (m_Position != m_ArchiveInfo.StartPosition)
@@ -789,7 +770,7 @@ HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *pr
SafeReadBytes(buf, kBufSize);
ecd64.Parse(buf);
- IncreaseRealPosition(recordSize - kZip64EcdSize);
+ Skip(recordSize - kZip64EcdSize);
if (!ReadUInt32(m_Signature))
return S_FALSE;
if (ecd64.thisDiskNumber != 0 || ecd64.startCDDiskNumber != 0)
@@ -838,6 +819,8 @@ HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items, CProgressVirt *pr
(!items.IsEmpty())))
return S_FALSE;
+ _inBufMode = false;
+ _inBuffer.Free();
return S_OK;
}
diff --git a/CPP/7zip/Archive/Zip/ZipIn.h b/CPP/7zip/Archive/Zip/ZipIn.h
index 750095d6..5f4fe143 100755
--- a/CPP/7zip/Archive/Zip/ZipIn.h
+++ b/CPP/7zip/Archive/Zip/ZipIn.h
@@ -4,8 +4,11 @@
#define __ZIP_IN_H
#include "Common/MyCom.h"
+
#include "../../IStream.h"
+#include "../../Common/InBuffer.h"
+
#include "ZipHeader.h"
#include "ZipItemEx.h"
@@ -65,13 +68,14 @@ class CInArchive
UInt32 m_Signature;
UInt64 m_StreamStartPosition;
UInt64 m_Position;
- AString m_NameBuffer;
+
+ bool _inBufMode;
+ CInBuffer _inBuffer;
HRESULT Seek(UInt64 offset);
HRESULT FindAndReadMarker(IInStream *stream, const UInt64 *searchHeaderSizeLimit);
- bool ReadUInt32(UInt32 &signature);
- AString ReadFileName(UInt32 nameSize);
+ void ReadFileName(UInt32 nameSize, AString &dest);
HRESULT ReadBytes(void *data, UInt32 size, UInt32 *processedSize);
bool ReadBytesAndTestSize(void *data, UInt32 size);
@@ -81,7 +85,9 @@ class CInArchive
UInt16 ReadUInt16();
UInt32 ReadUInt32();
UInt64 ReadUInt64();
+ bool ReadUInt32(UInt32 &signature);
+ void Skip(UInt64 num);
void IncreaseRealPosition(UInt64 addValue);
void ReadExtra(UInt32 extraSize, CExtraBlock &extraBlock,
diff --git a/CPP/7zip/Archive/Zip/ZipItem.cpp b/CPP/7zip/Archive/Zip/ZipItem.cpp
index 03472d85..139b0129 100755
--- a/CPP/7zip/Archive/Zip/ZipItem.cpp
+++ b/CPP/7zip/Archive/Zip/ZipItem.cpp
@@ -51,6 +51,31 @@ bool CExtraSubBlock::ExtractNtfsTime(int index, FILETIME &ft) const
return false;
}
+bool CExtraSubBlock::ExtractUnixTime(int index, UInt32 &res) const
+{
+ res = 0;
+ UInt32 size = (UInt32)Data.GetCapacity();
+ if (ID != NFileHeader::NExtraID::kUnixTime || size < 5)
+ return false;
+ const Byte *p = (const Byte *)Data;
+ Byte flags = *p++;
+ size--;
+ for (int i = 0; i < 3; i++)
+ if ((flags & (1 << i)) != 0)
+ {
+ if (size < 4)
+ return false;
+ if (index == i)
+ {
+ res = GetUi32(p);
+ return true;
+ }
+ p += 4;
+ size -= 4;
+ }
+ return false;
+}
+
bool CLocalItem::IsDir() const
{
return NItemName::HasTailSlash(Name, GetCodePage());
diff --git a/CPP/7zip/Archive/Zip/ZipItem.h b/CPP/7zip/Archive/Zip/ZipItem.h
index c0f780f8..31f2de73 100755
--- a/CPP/7zip/Archive/Zip/ZipItem.h
+++ b/CPP/7zip/Archive/Zip/ZipItem.h
@@ -28,6 +28,7 @@ struct CExtraSubBlock
UInt16 ID;
CByteBuffer Data;
bool ExtractNtfsTime(int index, FILETIME &ft) const;
+ bool ExtractUnixTime(int index, UInt32 &res) const;
};
struct CWzAesExtraField
@@ -151,6 +152,17 @@ struct CExtraBlock
return false;
}
+ bool GetUnixTime(int index, UInt32 &res) const
+ {
+ for (int i = 0; i < SubBlocks.Size(); i++)
+ {
+ const CExtraSubBlock &sb = SubBlocks[i];
+ if (sb.ID == NFileHeader::NExtraID::kUnixTime)
+ return sb.ExtractUnixTime(index, res);
+ }
+ return false;
+ }
+
/*
bool HasStrongCryptoField() const
{
diff --git a/CPP/7zip/Archive/Zip/ZipRegister.cpp b/CPP/7zip/Archive/Zip/ZipRegister.cpp
index 12db3e44..2fd36950 100755
--- a/CPP/7zip/Archive/Zip/ZipRegister.cpp
+++ b/CPP/7zip/Archive/Zip/ZipRegister.cpp
@@ -13,6 +13,6 @@ static IOutArchive *CreateArcOut() { return new NArchive::NZip::CHandler; }
#endif
static CArcInfo g_ArcInfo =
- { L"Zip", L"zip jar xpi", 0, 1, { 0x50, 0x4B, 0x03, 0x04 }, 4, false, CreateArc, CreateArcOut };
+ { L"Zip", L"zip jar xpi odt ods docx xlsx", 0, 1, { 0x50, 0x4B, 0x03, 0x04 }, 4, false, CreateArc, CreateArcOut };
REGISTER_ARC(Zip)
diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.cpp b/CPP/7zip/Archive/Zip/ZipUpdate.cpp
index 5c7e64db..c76ee488 100755
--- a/CPP/7zip/Archive/Zip/ZipUpdate.cpp
+++ b/CPP/7zip/Archive/Zip/ZipUpdate.cpp
@@ -47,8 +47,7 @@ static HRESULT CopyBlockToArchive(ISequentialInStream *inStream,
{
CMyComPtr<ISequentialOutStream> outStream;
outArchive.CreateStreamForCopying(&outStream);
- CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;
- return copyCoder->Code(inStream, outStream, NULL, NULL, progress);
+ return NCompress::CopyStream(inStream, outStream, progress);
}
static HRESULT WriteRange(IInStream *inStream, COutArchive &outArchive,