Update to 7-Zip 17.00 Beta

This commit is contained in:
Tino Reichardt
2017-04-30 14:14:14 +02:00
parent 54389d6e2f
commit aa5ba75da0
451 changed files with 15746 additions and 8574 deletions

View File

@@ -104,20 +104,18 @@ static const char * const kHostOS[] =
, "BeOS"
};
static const char *kUnknownOS = "Unknown";
static const CUInt32PCharPair k_Flags[] =
static const char * const k_Flags[] =
{
{ 0, "Volume" },
{ 1, "Comment" },
{ 2, "Lock" },
{ 3, "Solid" },
{ 4, "NewVolName" }, // pack_comment in old versuons
{ 5, "Authenticity" },
{ 6, "Recovery" },
{ 7, "BlockEncryption" },
{ 8, "FirstVolume" },
{ 9, "EncryptVer" }
"Volume"
, "Comment"
, "Lock"
, "Solid"
, "NewVolName" // pack_comment in old versuons
, "Authenticity"
, "Recovery"
, "BlockEncryption"
, "FirstVolume"
, "EncryptVer" // 9
};
enum EErrorType
@@ -132,13 +130,13 @@ class CInArchive
{
IInStream *m_Stream;
UInt64 m_StreamStartPosition;
CBuffer<wchar_t> _unicodeNameBuffer;
UString _unicodeNameBuffer;
CByteBuffer _comment;
CByteBuffer m_FileHeaderData;
NHeader::NBlock::CBlock m_BlockHeader;
NCrypto::NRar3::CDecoder *m_RarAESSpec;
CMyComPtr<ICompressFilter> m_RarAES;
CBuffer<Byte> m_DecryptedData;
CByteBuffer m_DecryptedData;
Byte *m_DecryptedDataAligned;
UInt32 m_DecryptedDataSize;
bool m_CryptoMode;
@@ -272,14 +270,19 @@ bool CInArchive::ReadBytesAndTestSize(void *data, UInt32 size)
return processed == size;
}
static void DecodeUnicodeFileName(const Byte *name, const Byte *encName,
static unsigned DecodeUnicodeFileName(const Byte *name, const Byte *encName,
unsigned encSize, wchar_t *unicodeName, unsigned maxDecSize)
{
unsigned encPos = 0;
unsigned decPos = 0;
unsigned flagBits = 0;
Byte flags = 0;
Byte highByte = encName[encPos++];
if (encPos >= encSize)
return 0; // error
const unsigned highBits = ((unsigned)encName[encPos++]) << 8;
while (encPos < encSize && decPos < maxDecSize)
{
if (flagBits == 0)
@@ -287,40 +290,46 @@ static void DecodeUnicodeFileName(const Byte *name, const Byte *encName,
flags = encName[encPos++];
flagBits = 8;
}
switch (flags >> 6)
{
case 0:
unicodeName[decPos++] = encName[encPos++];
break;
case 1:
unicodeName[decPos++] = (wchar_t)(encName[encPos++] + (highByte << 8));
break;
case 2:
unicodeName[decPos++] = (wchar_t)(encName[encPos] + (encName[encPos + 1] << 8));
encPos += 2;
break;
case 3:
{
unsigned len = encName[encPos++];
if (len & 0x80)
{
Byte correction = encName[encPos++];
for (len = (len & 0x7f) + 2;
len > 0 && decPos < maxDecSize; len--, decPos++)
unicodeName[decPos] = (wchar_t)(((name[decPos] + correction) & 0xff) + (highByte << 8));
}
else
for (len += 2; len > 0 && decPos < maxDecSize; len--, decPos++)
unicodeName[decPos] = name[decPos];
}
break;
}
flags <<= 2;
if (encPos >= encSize)
break; // error
unsigned len = encName[encPos++];
flagBits -= 2;
const unsigned mode = (flags >> flagBits) & 3;
if (mode != 3)
{
if (mode == 1)
len += highBits;
else if (mode == 2)
{
if (encPos >= encSize)
break; // error
len += ((unsigned)encName[encPos++] << 8);
}
unicodeName[decPos++] = (wchar_t)len;
}
else
{
if (len & 0x80)
{
if (encPos >= encSize)
break; // error
Byte correction = encName[encPos++];
for (len = (len & 0x7f) + 2; len > 0 && decPos < maxDecSize; len--, decPos++)
unicodeName[decPos] = (wchar_t)(((name[decPos] + correction) & 0xff) + highBits);
}
else
for (len += 2; len > 0 && decPos < maxDecSize; len--, decPos++)
unicodeName[decPos] = name[decPos];
}
}
unicodeName[decPos < maxDecSize ? decPos : maxDecSize - 1] = 0;
return decPos < maxDecSize ? decPos : maxDecSize - 1;
}
void CInArchive::ReadName(const Byte *p, unsigned nameSize, CItem &item)
{
item.UnicodeName.Empty();
@@ -336,8 +345,8 @@ void CInArchive::ReadName(const Byte *p, unsigned nameSize, CItem &item)
{
i++;
unsigned uNameSizeMax = MyMin(nameSize, (unsigned)0x400);
_unicodeNameBuffer.AllocAtLeast(uNameSizeMax + 1);
DecodeUnicodeFileName(p, p + i, nameSize - i, _unicodeNameBuffer, uNameSizeMax);
unsigned len = DecodeUnicodeFileName(p, p + i, nameSize - i, _unicodeNameBuffer.GetBuf(uNameSizeMax), uNameSizeMax);
_unicodeNameBuffer.ReleaseBuf_SetEnd(len);
item.UnicodeName = _unicodeNameBuffer;
}
else if (!ConvertUTF8ToUnicode(item.Name, item.UnicodeName))
@@ -818,7 +827,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
case kpidSolid: prop = _arcInfo.IsSolid(); break;
case kpidCharacts:
{
AString s = FlagsToString(k_Flags, ARRAY_SIZE(k_Flags), _arcInfo.Flags);
AString s (FlagsToString(k_Flags, ARRAY_SIZE(k_Flags), _arcInfo.Flags));
// FLAGS_TO_PROP(k_Flags, _arcInfo.Flags, prop);
if (_arcInfo.Is_DataCRC_Defined())
{
@@ -871,8 +880,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
if (/* &_missingVol || */ !_missingVolName.IsEmpty())
{
UString s;
s.SetFromAscii("Missing volume : ");
UString s ("Missing volume : ");
s += _missingVolName;
prop = s;
}
@@ -900,13 +908,11 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
{
if (_arcInfo.Is_VolNumber_Defined())
{
char sz[16];
ConvertUInt32ToString((UInt32)_arcInfo.VolNumber + 1, sz);
unsigned len = MyStringLen(sz);
AString s = "part";
for (; len < 2; len++)
AString s ("part");
UInt32 v = (UInt32)_arcInfo.VolNumber + 1;
if (v < 10)
s += '0';
s += sz;
s.Add_UInt32(v);
s += ".rar";
prop = s;
}
@@ -974,7 +980,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
u = mainItem->GetName();
u += item.GetName();
*/
prop = (const wchar_t *)NItemName::WinNameToOSName(item.GetName());
prop = (const wchar_t *)NItemName::WinPathToOsPath(item.GetName());
break;
}
case kpidIsDir: prop = item.IsDir(); break;
@@ -1015,7 +1021,9 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
prop = s;
break;
}
case kpidHostOS: prop = (item.HostOS < ARRAY_SIZE(kHostOS)) ? kHostOS[item.HostOS] : kUnknownOS; break;
case kpidHostOS:
TYPE_TO_PROP(kHostOS, item.HostOS, prop);
break;
}
prop.Detach(value);
return S_OK;
@@ -1324,7 +1332,13 @@ STDMETHODIMP CVolsInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
if (_curIndex >= _refItem.NumItems)
break;
const CItem &item = (*_items)[_refItem.ItemIndex + _curIndex];
IInStream *s = (*_arcs)[_refItem.VolumeIndex + _curIndex].Stream;
unsigned volIndex = _refItem.VolumeIndex + _curIndex;
if (volIndex >= _arcs->Size())
{
return S_OK;
// return S_FALSE;
}
IInStream *s = (*_arcs)[volIndex].Stream;
RINOK(s->Seek(item.GetDataPosition(), STREAM_SEEK_SET, NULL));
_stream = s;
_calcCrc = (CrcIsOK && item.IsSplitAfter());