aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Archive/ComHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/Archive/ComHandler.cpp')
-rw-r--r--CPP/7zip/Archive/ComHandler.cpp48
1 files changed, 25 insertions, 23 deletions
diff --git a/CPP/7zip/Archive/ComHandler.cpp b/CPP/7zip/Archive/ComHandler.cpp
index 82d939d..144369e 100644
--- a/CPP/7zip/Archive/ComHandler.cpp
+++ b/CPP/7zip/Archive/ComHandler.cpp
@@ -68,7 +68,7 @@ namespace NItemType
68 static const Byte kRootStorage = 5; 68 static const Byte kRootStorage = 5;
69} 69}
70 70
71static const UInt32 kNameSizeMax = 64; 71static const unsigned kNameSizeMax = 64;
72 72
73struct CItem 73struct CItem
74{ 74{
@@ -98,30 +98,30 @@ struct CRef
98 98
99class CDatabase 99class CDatabase
100{ 100{
101 UInt32 NumSectorsInMiniStream;
102 CObjArray<UInt32> MiniSids; 101 CObjArray<UInt32> MiniSids;
103 102
104 HRESULT AddNode(int parent, UInt32 did); 103 HRESULT AddNode(int parent, UInt32 did);
105public:
106 104
105public:
107 CObjArray<UInt32> Fat; 106 CObjArray<UInt32> Fat;
108 UInt32 FatSize;
109
110 CObjArray<UInt32> Mat; 107 CObjArray<UInt32> Mat;
111 UInt32 MatSize;
112
113 CObjectVector<CItem> Items; 108 CObjectVector<CItem> Items;
114 CRecordVector<CRef> Refs; 109 CRecordVector<CRef> Refs;
110private:
111 UInt32 NumSectorsInMiniStream;
112public:
113 UInt32 MatSize;
114 UInt32 FatSize;
115 115
116 UInt32 LongStreamMinSize; 116 UInt32 LongStreamMinSize;
117 unsigned SectorSizeBits; 117 unsigned SectorSizeBits;
118 unsigned MiniSectorSizeBits; 118 unsigned MiniSectorSizeBits;
119 119
120 Int32 MainSubfile; 120 Int32 MainSubfile;
121 EType Type;
121 122
122 UInt64 PhySize; 123 UInt64 PhySize;
123 UInt64 PhySize_Aligned; 124 UInt64 PhySize_Aligned;
124 EType Type;
125 125
126 bool IsNotArcType() const 126 bool IsNotArcType() const
127 { 127 {
@@ -148,14 +148,14 @@ public:
148 148
149 UInt64 GetItemPackSize(UInt64 size) const 149 UInt64 GetItemPackSize(UInt64 size) const
150 { 150 {
151 UInt64 mask = ((UInt64)1 << (IsLargeStream(size) ? SectorSizeBits : MiniSectorSizeBits)) - 1; 151 const UInt64 mask = ((UInt32)1 << (IsLargeStream(size) ? SectorSizeBits : MiniSectorSizeBits)) - 1;
152 return (size + mask) & ~mask; 152 return (size + mask) & ~mask;
153 } 153 }
154 154
155 bool GetMiniCluster(UInt32 sid, UInt64 &res) const 155 bool GetMiniCluster(UInt32 sid, UInt64 &res) const
156 { 156 {
157 unsigned subBits = SectorSizeBits - MiniSectorSizeBits; 157 const unsigned subBits = SectorSizeBits - MiniSectorSizeBits;
158 UInt32 fid = sid >> subBits; 158 const UInt32 fid = sid >> subBits;
159 if (fid >= NumSectorsInMiniStream) 159 if (fid >= NumSectorsInMiniStream)
160 return false; 160 return false;
161 res = (((UInt64)MiniSids[fid] + 1) << subBits) + (sid & ((1 << subBits) - 1)); 161 res = (((UInt64)MiniSids[fid] + 1) << subBits) + (sid & ((1 << subBits) - 1));
@@ -177,7 +177,7 @@ HRESULT CDatabase::ReadSector(IInStream *inStream, Byte *buf, unsigned sectorSiz
177HRESULT CDatabase::ReadIDs(IInStream *inStream, Byte *buf, unsigned sectorSizeBits, UInt32 sid, UInt32 *dest) 177HRESULT CDatabase::ReadIDs(IInStream *inStream, Byte *buf, unsigned sectorSizeBits, UInt32 sid, UInt32 *dest)
178{ 178{
179 RINOK(ReadSector(inStream, buf, sectorSizeBits, sid)) 179 RINOK(ReadSector(inStream, buf, sectorSizeBits, sid))
180 UInt32 sectorSize = (UInt32)1 << sectorSizeBits; 180 const UInt32 sectorSize = (UInt32)1 << sectorSizeBits;
181 for (UInt32 t = 0; t < sectorSize; t += 4) 181 for (UInt32 t = 0; t < sectorSize; t += 4)
182 *dest++ = Get32(buf + t); 182 *dest++ = Get32(buf + t);
183 return S_OK; 183 return S_OK;
@@ -373,7 +373,7 @@ UString CDatabase::GetItemPath(UInt32 index) const
373HRESULT CDatabase::Update_PhySize_WithItem(unsigned index) 373HRESULT CDatabase::Update_PhySize_WithItem(unsigned index)
374{ 374{
375 const CItem &item = Items[index]; 375 const CItem &item = Items[index];
376 bool isLargeStream = (index == 0 || IsLargeStream(item.Size)); 376 const bool isLargeStream = (index == 0 || IsLargeStream(item.Size));
377 if (!isLargeStream) 377 if (!isLargeStream)
378 return S_OK; 378 return S_OK;
379 const unsigned bsLog = isLargeStream ? SectorSizeBits : MiniSectorSizeBits; 379 const unsigned bsLog = isLargeStream ? SectorSizeBits : MiniSectorSizeBits;
@@ -527,6 +527,10 @@ HRESULT CDatabase::Open(IInStream *inStream)
527 { 527 {
528 CItem item; 528 CItem item;
529 item.Parse(sect + i, mode64bit); 529 item.Parse(sect + i, mode64bit);
530 // we use (item.Size) check here.
531 // so we don't need additional overflow checks for (item.Size +) in another code
532 if (item.Size >= ((UInt64)1 << 63))
533 return S_FALSE;
530 Items.Add(item); 534 Items.Add(item);
531 } 535 }
532 sid = Fat[sid]; 536 sid = Fat[sid];
@@ -767,11 +771,8 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
767 UInt64 totalPackSize; 771 UInt64 totalPackSize;
768 totalSize = totalPackSize = 0; 772 totalSize = totalPackSize = 0;
769 773
770 NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder(); 774 CMyComPtr2_Create<ICompressCoder, NCompress::CCopyCoder> copyCoder;
771 CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec; 775 CMyComPtr2_Create<ICompressProgressInfo, CLocalProgress> lps;
772
773 CLocalProgress *lps = new CLocalProgress;
774 CMyComPtr<ICompressProgressInfo> progress = lps;
775 lps->Init(extractCallback, false); 776 lps->Init(extractCallback, false);
776 777
777 for (i = 0; i < numItems; i++) 778 for (i = 0; i < numItems; i++)
@@ -781,7 +782,8 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
781 RINOK(lps->SetCur()) 782 RINOK(lps->SetCur())
782 const UInt32 index = allFilesMode ? i : indices[i]; 783 const UInt32 index = allFilesMode ? i : indices[i];
783 const CItem &item = _db.Items[_db.Refs[index].Did]; 784 const CItem &item = _db.Items[_db.Refs[index].Did];
784 785 Int32 res;
786 {
785 CMyComPtr<ISequentialOutStream> outStream; 787 CMyComPtr<ISequentialOutStream> outStream;
786 const Int32 askMode = testMode ? 788 const Int32 askMode = testMode ?
787 NExtract::NAskMode::kTest : 789 NExtract::NAskMode::kTest :
@@ -801,7 +803,7 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
801 if (!testMode && !outStream) 803 if (!testMode && !outStream)
802 continue; 804 continue;
803 RINOK(extractCallback->PrepareOperation(askMode)) 805 RINOK(extractCallback->PrepareOperation(askMode))
804 Int32 res = NExtract::NOperationResult::kDataError; 806 res = NExtract::NOperationResult::kDataError;
805 CMyComPtr<ISequentialInStream> inStream; 807 CMyComPtr<ISequentialInStream> inStream;
806 HRESULT hres = GetStream(index, &inStream); 808 HRESULT hres = GetStream(index, &inStream);
807 if (hres == S_FALSE) 809 if (hres == S_FALSE)
@@ -813,12 +815,12 @@ Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
813 RINOK(hres) 815 RINOK(hres)
814 if (inStream) 816 if (inStream)
815 { 817 {
816 RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress)) 818 RINOK(copyCoder.Interface()->Code(inStream, outStream, NULL, NULL, lps))
817 if (copyCoderSpec->TotalSize == item.Size) 819 if (copyCoder->TotalSize == item.Size)
818 res = NExtract::NOperationResult::kOK; 820 res = NExtract::NOperationResult::kOK;
819 } 821 }
820 } 822 }
821 outStream.Release(); 823 }
822 RINOK(extractCallback->SetOperationResult(res)) 824 RINOK(extractCallback->SetOperationResult(res))
823 } 825 }
824 return S_OK; 826 return S_OK;