This commit is contained in:
Igor Pavlov
2021-07-22 23:00:14 +01:00
committed by Kornel
parent 4a960640a3
commit 585698650f
619 changed files with 34904 additions and 10859 deletions
+29 -16
View File
@@ -41,9 +41,9 @@ static const unsigned kNumDirLevelsMax = (1 << 10);
#define Get64(p) (be ? GetBe64(p) : GetUi64(p))
*/
UInt16 Get16b(const Byte *p, bool be) { return be ? GetBe16(p) : GetUi16(p); }
UInt32 Get32b(const Byte *p, bool be) { return be ? GetBe32(p) : GetUi32(p); }
UInt64 Get64b(const Byte *p, bool be) { return be ? GetBe64(p) : GetUi64(p); }
static UInt16 Get16b(const Byte *p, bool be) { return be ? GetBe16(p) : GetUi16(p); }
static UInt32 Get32b(const Byte *p, bool be) { return be ? GetBe32(p) : GetUi32(p); }
static UInt64 Get64b(const Byte *p, bool be) { return be ? GetBe64(p) : GetUi64(p); }
#define Get16(p) Get16b(p, be)
#define Get32(p) Get32b(p, be)
@@ -121,6 +121,10 @@ static const char * const k_Flags[] =
, "ALWAYS_FRAGMENTS"
, "DUPLICATES_REMOVED"
, "EXPORTABLE"
, "UNCOMPRESSED_XATTRS"
, "NO_XATTRS"
, "COMPRESSOR_OPTIONS"
, "UNCOMPRESSED_IDS"
};
static const UInt32 kNotCompressedBit16 = (1 << 15);
@@ -129,10 +133,10 @@ static const UInt32 kNotCompressedBit32 = (1 << 24);
#define GET_COMPRESSED_BLOCK_SIZE(size) ((size) & ~kNotCompressedBit32)
#define IS_COMPRESSED_BLOCK(size) (((size) & kNotCompressedBit32) == 0)
static const UInt32 kHeaderSize1 = 0x33;
static const UInt32 kHeaderSize2 = 0x3F;
// static const UInt32 kHeaderSize1 = 0x33;
// static const UInt32 kHeaderSize2 = 0x3F;
static const UInt32 kHeaderSize3 = 0x77;
static const UInt32 kHeaderSize4 = 0x60;
// static const UInt32 kHeaderSize4 = 0x60;
struct CHeader
{
@@ -1243,7 +1247,8 @@ HRESULT CHandler::Decompress(ISequentialOutStream *outStream, Byte *outBuf, bool
&status, &g_Alloc);
if (res != 0)
return SResToHRESULT(res);
if (status != LZMA_STATUS_FINISHED_WITH_MARK)
if (status != LZMA_STATUS_FINISHED_WITH_MARK
&& status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
return S_FALSE;
}
else
@@ -1310,7 +1315,7 @@ HRESULT CHandler::ReadData(CData &data, UInt64 start, UInt64 end)
{
if (end < start || end - start >= ((UInt64)1 << 32))
return S_FALSE;
UInt32 size = (UInt32)(end - start);
const UInt32 size = (UInt32)(end - start);
RINOK(_stream->Seek(start, STREAM_SEEK_SET, NULL));
_dynOutStreamSpec->Init();
UInt32 packPos = 0;
@@ -1322,8 +1327,11 @@ HRESULT CHandler::ReadData(CData &data, UInt64 start, UInt64 end)
return S_FALSE;
UInt32 packSize = size - packPos;
RINOK(ReadMetadataBlock(packSize));
if (_dynOutStreamSpec->GetSize() >= ((UInt64)1 << 32))
return S_FALSE;
{
const size_t tSize = _dynOutStreamSpec->GetSize();
if (tSize != (UInt32)tSize)
return S_FALSE;
}
packPos += packSize;
}
data.UnpackPos.Add((UInt32)_dynOutStreamSpec->GetSize());
@@ -1487,7 +1495,7 @@ HRESULT CHandler::OpenDir(int parent, UInt32 startBlock, UInt32 offset, unsigned
if (_openCodePage == CP_UTF8)
{
tempString.SetFrom_CalcLen((const char *)p, size);
if (!CheckUTF8(tempString))
if (!CheckUTF8_AString(tempString))
_openCodePage = CP_OEMCP;
}
@@ -1608,11 +1616,14 @@ HRESULT CHandler::Open2(IInStream *inStream)
{
UInt32 pos = 0;
UInt32 totalSize = (UInt32)_inodesData.Data.Size();
const unsigned kMinNodeParseSize = 4;
if (_h.NumInodes > totalSize / kMinNodeParseSize)
return S_FALSE;
_nodesPos.ClearAndReserve(_h.NumInodes);
_nodes.ClearAndReserve(_h.NumInodes);
// we use _blockToNode for binary search seed optimizations
_blockToNode.ClearAndReserve(_inodesData.GetNumBlocks() + 1);
int curBlock = 0;
unsigned curBlock = 0;
for (UInt32 i = 0; i < _h.NumInodes; i++)
{
CNode n;
@@ -2090,9 +2101,9 @@ HRESULT CHandler::ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize)
bool compressed;
if (blockIndex < _blockCompressed.Size())
{
compressed = _blockCompressed[(int)blockIndex];
blockOffset = _blockOffsets[(int)blockIndex];
packBlockSize = (UInt32)(_blockOffsets[(int)blockIndex + 1] - blockOffset);
compressed = _blockCompressed[(unsigned)blockIndex];
blockOffset = _blockOffsets[(unsigned)blockIndex];
packBlockSize = (UInt32)(_blockOffsets[(unsigned)blockIndex + 1] - blockOffset);
blockOffset += node.StartBlock;
}
else
@@ -2126,14 +2137,16 @@ HRESULT CHandler::ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize)
bool outBufWasWritten;
UInt32 outBufWasWrittenSize;
HRESULT res = Decompress(_outStream, _cachedBlock, &outBufWasWritten, &outBufWasWrittenSize, packBlockSize, _h.BlockSize);
RINOK(res);
if (outBufWasWritten)
_cachedUnpackBlockSize = outBufWasWrittenSize;
else
_cachedUnpackBlockSize = (UInt32)_outStreamSpec->GetPos();
RINOK(res);
}
else
{
if (packBlockSize > _h.BlockSize)
return S_FALSE;
RINOK(ReadStream_FALSE(_limitedInStream, _cachedBlock, packBlockSize));
_cachedUnpackBlockSize = packBlockSize;
}