Merged PR 988738: Fix some problems with asserts and ensure that xPlatAppx project always uses

Fix some problems with asserts and ensure that xPlatAppx project always uses C++14

Related work items: #14265946
This commit is contained in:
Phil Smith 2017-10-17 17:05:10 +00:00
Родитель 9a13c65c0d
Коммит 144959a64b
7 изменённых файлов: 105 добавлений и 99 удалений

Просмотреть файл

@ -90,6 +90,8 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;XPLATAPPX_API</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp14</LanguageStandard>
<EnableModules>false</EnableModules>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -103,6 +105,8 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;XPLATAPPX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp14</LanguageStandard>
<EnableModules>false</EnableModules>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -116,8 +120,10 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;XPLATAPPX_API</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;WIN32;XPLATAPPX_API</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp14</LanguageStandard>
<EnableModules>false</EnableModules>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -135,6 +141,8 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;XPLATAPPX_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp14</LanguageStandard>
<EnableModules>false</EnableModules>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>

Просмотреть файл

@ -15,33 +15,33 @@ namespace xPlat {
//
// Win32 error codes
//
NotSupported = 0x80070032,
InvalidParameter = 0x80070057,
NotImplemented = 0x80070078,
NotSupported = 0x80070032,
InvalidParameter = 0x80070057,
NotImplemented = 0x80070078,
//
// xPlat specific error codes
//
// Basic file errors
FileOpen = ERROR_FACILITY + 0x0001,
FileSeek = ERROR_FACILITY + 0x0002,
FileRead = ERROR_FACILITY + 0x0003,
FileWrite = ERROR_FACILITY + 0x0003,
FileCreateDirectory = ERROR_FACILITY + 0x0004,
FileOpen = ERROR_FACILITY + 0x0001,
FileSeek = ERROR_FACILITY + 0x0002,
FileRead = ERROR_FACILITY + 0x0003,
FileWrite = ERROR_FACILITY + 0x0003,
FileCreateDirectory = ERROR_FACILITY + 0x0004,
// Zip format errors
ZipCentralDirectoryHeader = ERROR_FACILITY + 0x0011,
ZipLocalFileHeader = ERROR_FACILITY + 0x0012,
Zip64EOCDRecord = ERROR_FACILITY + 0x0013,
Zip64EOCDLocator = ERROR_FACILITY + 0x0014,
ZipEOCDRecord = ERROR_FACILITY + 0x0015,
ZipHiddenData = ERROR_FACILITY + 0x0016,
ZipCentralDirectoryHeader = ERROR_FACILITY + 0x0011,
ZipLocalFileHeader = ERROR_FACILITY + 0x0012,
Zip64EOCDRecord = ERROR_FACILITY + 0x0013,
Zip64EOCDLocator = ERROR_FACILITY + 0x0014,
ZipEOCDRecord = ERROR_FACILITY + 0x0015,
ZipHiddenData = ERROR_FACILITY + 0x0016,
// Inflate errors
InflateInitialize = ERROR_FACILITY + 0x0021,
InflateRead = ERROR_FACILITY + 0x0022,
InflateCorruptData = ERROR_FACILITY + 0x0023,
InflateInitialize = ERROR_FACILITY + 0x0021,
InflateRead = ERROR_FACILITY + 0x0022,
InflateCorruptData = ERROR_FACILITY + 0x0023,
};
// Defines a common exception type to throw in exceptional cases. DO NOT USE FOR FLOW CONTROL!
@ -50,51 +50,47 @@ namespace xPlat {
{
public:
Exception(Error error) : m_code(static_cast<std::uint32_t>(error))
{
assert(false);
}
{}
Exception(Error error, std::string& message) :
m_code(static_cast<std::uint32_t>(error)),
m_message(message)
{
assert(false);
}
{}
Exception(Error error, const char* message) :
m_code(static_cast<std::uint32_t>(error)),
m_message(message)
{
assert(false);
}
{}
Exception(std::uint32_t error) : m_code(0x8007 + error)
{
assert(false);
}
{}
Exception(std::uint32_t error, std::string& message) :
m_code(0x8007 + error),
m_message(message)
{
assert(false);
}
{}
Exception(std::uint32_t error, const char* message) :
m_code(0x8007 + error),
m_message(message)
{
assert(false);
}
{}
uint32_t Code() { return m_code; }
std::string& Message() { return m_message; }
uint32_t Code() { return m_code; }
std::string& Message() { return m_message; }
protected:
std::uint32_t m_code;
std::string m_message;
};
// Helper to make code more terse and more readable at the same time.
#define ThrowIf(c, a, m) {if (!(a)) throw xPlat::Exception(c,m);}
}
// Helper to make code more terse and more readable at the same time.
#define ThrowErrorIfNot(c, a, m) \
{ \
if (!(a)) \
{ \
assert(false); \
throw xPlat::Exception(c,m); \
} \
}

Просмотреть файл

@ -18,7 +18,7 @@ namespace xPlat {
{
static const char* modes[] = { "rb", "wb", "ab", "r+b", "w+b", "a+b" };
file = std::fopen(path.c_str(), modes[mode]);
ThrowIf(Error::FileOpen, (file), path.c_str());
ThrowErrorIfNot(Error::FileOpen, (file), path.c_str());
}
virtual ~FileStream() override
@ -38,7 +38,7 @@ namespace xPlat {
virtual void Seek(std::uint64_t to, StreamBase::Reference whence) override
{
int rc = std::fseek(file, to, whence);
ThrowIf(Error::FileSeek, (rc == 0), "seek failed");
ThrowErrorIfNot(Error::FileSeek, (rc == 0), "seek failed");
offset = Ftell();
}
@ -47,7 +47,7 @@ namespace xPlat {
std::size_t bytesRead = std::fread(
static_cast<void*>(const_cast<std::uint8_t*>(bytes)), 1, size, file
);
ThrowIf(Error::FileRead, (bytesRead == size || Feof()), "read failed");
ThrowErrorIfNot(Error::FileRead, (bytesRead == size || Feof()), "read failed");
offset = Ftell();
return bytesRead;
}
@ -67,7 +67,7 @@ namespace xPlat {
std::size_t bytesWritten = std::fwrite(
static_cast<void*>(const_cast<std::uint8_t*>(bytes)), 1, size, file
);
ThrowIf(Error::FileWrite, (bytesWritten == size), "write failed");
ThrowErrorIfNot(Error::FileWrite, (bytesWritten == size), "write failed");
offset = Ftell();
}

Просмотреть файл

@ -31,13 +31,13 @@ namespace xPlat {
m_fileCurrentWindowPositionEnd = 0;
int ret = inflateInit2(&m_zstrm, -MAX_WBITS);
ThrowIf(Error::InflateInitialize, (ret == Z_OK), "inflateInit2 failed");
ThrowErrorIfNot(Error::InflateInitialize, (ret == Z_OK), "inflateInit2 failed");
return std::make_pair(true, State::READY_TO_READ);
}
}, // State::UNINITIALIZED
{ State::READY_TO_READ , [&](std::size_t, const std::uint8_t*)
{
ThrowIf(Error::InflateRead,(m_zstrm.avail_in == 0), "uninflated bytes overwritten");
ThrowErrorIfNot(Error::InflateRead,(m_zstrm.avail_in == 0), "uninflated bytes overwritten");
m_zstrm.avail_in = m_stream->Read(InflateStream::BUFFERSIZE, m_compressedBuffer);
m_zstrm.next_in = m_compressedBuffer;
return std::make_pair(true, State::READY_TO_INFLATE);
@ -55,7 +55,7 @@ namespace xPlat {
case Z_DATA_ERROR:
case Z_MEM_ERROR:
Cleanup();
ThrowIf(Error::InflateCorruptData, false, "inflate failed unexpectedly.");
ThrowErrorIfNot(Error::InflateCorruptData, false, "inflate failed unexpectedly.");
case Z_STREAM_END:
default:
m_fileCurrentWindowPositionEnd += (InflateStream::BUFFERSIZE - m_zstrm.avail_out);
@ -68,7 +68,7 @@ namespace xPlat {
// Check if we're actually at the end of stream.
if (0 == (m_uncompressedSize - m_fileCurrentPosition))
{
ThrowIf(Error::InflateCorruptData, ((m_zret != Z_STREAM_END) || (m_zstrm.avail_in != 0)), "unexpected extra data");
ThrowErrorIfNot(Error::InflateCorruptData, ((m_zret != Z_STREAM_END) || (m_zstrm.avail_in != 0)), "unexpected extra data");
return std::make_pair(true, State::CLEANUP);
}

Просмотреть файл

@ -78,7 +78,7 @@ namespace xPlat {
{
return;
}
ThrowIf(lastError, false, "FindFirstFile failed.");
ThrowErrorIfNot(lastError, false, "FindFirstFile failed.");
}
do
@ -114,7 +114,7 @@ namespace xPlat {
while (FindNextFile(find.get(), &findFileData));
std::uint32_t lastError = static_cast<std::uint32_t>(GetLastError());
ThrowIf(lastError,
ThrowErrorIfNot(lastError,
((lastError == ERROR_NO_MORE_FILES) ||
(lastError == ERROR_SUCCESS) ||
(lastError == ERROR_ALREADY_EXISTS)),
@ -192,7 +192,7 @@ namespace xPlat {
if (!CreateDirectory(utf16Name.c_str(), nullptr))
{
auto lastError = static_cast<std::uint32_t>(GetLastError());
ThrowIf(lastError, (lastError == ERROR_ALREADY_EXISTS), "CreateDirectory");
ThrowErrorIfNot(lastError, (lastError == ERROR_ALREADY_EXISTS), "CreateDirectory");
}
}
path = path + GetPathSeparator() + PopFirst();

Просмотреть файл

@ -186,32 +186,32 @@ namespace xPlat {
{
// 0 - central file header signature 4 bytes(0x02014b50)
Field<0>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader,
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader,
(v == static_cast<std::uint32_t>(Signatures::CentralFileHeader)),
"CDFH Signature");
};
// 1 - version made by 2 bytes
Field<1>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader,
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader,
(v == static_cast<std::uint16_t>(ZipVersions::Zip64FormatExtension)),
"unsupported version made by");
};
// 2 - version needed to extract 2 bytes
Field<2>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader,
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader,
((v == static_cast<std::uint16_t>(ZipVersions::Zip32DefaultVersion)) ||
(v == static_cast<std::uint16_t>(ZipVersions::Zip64FormatExtension))),
"unsupported version needed to extract");
};
// 3 - general purpose bit flag 2 bytes
Field<3>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader,
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader,
((v & static_cast<std::uint16_t>(UnsupportedFlagsMask)) == 0),
"unsupported flag(s) specified");
};
// 4 - compression method 2 bytes
Field<4>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader,
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader,
((v == static_cast<std::uint16_t>(CompressionType::Store)) ||
(v == static_cast<std::uint16_t>(CompressionType::Deflate))),
"unsupported compression method");
@ -223,30 +223,30 @@ namespace xPlat {
// 9 - uncompressed size 4 bytes
//10 - file name length 2 bytes
Field<10>().validation = [&](std::uint16_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader, (v != 0), "unsupported file name size");
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader, (v != 0), "unsupported file name size");
Field<17>().value.resize(v,0);
};
//11 - extra field length 2 bytes
Field<11>().validation = [&](std::uint16_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader, (v == 0), "unsupported extra field size");
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader, (v == 0), "unsupported extra field size");
Field<18>().value.resize(v,0);
};
//12 - file comment length 2 bytes
Field<12>().validation = [&](std::uint16_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader, (v == 0), "unsupported file comment size");
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader, (v == 0), "unsupported file comment size");
};
//13 - disk number start 2 bytes
Field<13>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader, (v == 0), "unsupported disk number start");
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader, (v == 0), "unsupported disk number start");
};
//14 - internal file attributes 2 bytes
Field<14>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader, (v == 0), "unsupported internal file attributes");
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader, (v == 0), "unsupported internal file attributes");
};
//15 - external file attributes 4 bytes
//16 - relative offset of local header 4 bytes
Field<16>().validation = [&](std::uint32_t& v)
{ ThrowIf(Error::ZipCentralDirectoryHeader, (v < m_stream->Ftell()), "invalid relative offset");
{ ThrowErrorIfNot(Error::ZipCentralDirectoryHeader, (v < m_stream->Ftell()), "invalid relative offset");
};
//17 - file name(variable size)
//18 - extra field(variable size)
@ -344,29 +344,29 @@ namespace xPlat {
{
// 0 - local file header signature 4 bytes(0x04034b50)
Field<0>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::ZipLocalFileHeader,
{ ThrowErrorIfNot(Error::ZipLocalFileHeader,
(v == static_cast<std::uint32_t>(Signatures::LocalFileHeader)),
"file header does not match signature");
};
// 1 - version needed to extract 2 bytes
Field<1>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipLocalFileHeader,
{ ThrowErrorIfNot(Error::ZipLocalFileHeader,
((v == static_cast<std::uint16_t>(ZipVersions::Zip32DefaultVersion)) ||
(v == static_cast<std::uint16_t>(ZipVersions::Zip64FormatExtension))),
"unsupported version needed to extract");
};
// 2 - general purpose bit flag 2 bytes
Field<2>().validation = [&](std::uint16_t& v)
{ ThrowIf(Error::ZipLocalFileHeader,
{ ThrowErrorIfNot(Error::ZipLocalFileHeader,
((v & static_cast<std::uint16_t>(UnsupportedFlagsMask)) == 0),
"unsupported flag(s) specified");
ThrowIf(Error::ZipLocalFileHeader,
ThrowErrorIfNot(Error::ZipLocalFileHeader,
(IsGeneralPurposeBitSet() == m_directoryEntry->IsGeneralPurposeBitSet()),
"inconsistent general purpose bits specified");
};
// 3 - compression method 2 bytes
Field<3>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipLocalFileHeader,
{ ThrowErrorIfNot(Error::ZipLocalFileHeader,
((v == static_cast<std::uint16_t>(CompressionType::Store)) ||
(v == static_cast<std::uint16_t>(CompressionType::Deflate)) ),
"unsupported compression method");
@ -375,24 +375,24 @@ namespace xPlat {
// 5 - last mod file date 2 bytes
// 6 - crc - 32 4 bytes
Field<6>().validation = [&](std::uint32_t& v)
{ ThrowIf(Error::ZipLocalFileHeader, (!IsGeneralPurposeBitSet() || (v == 0)), "Invalid CRC");
{ ThrowErrorIfNot(Error::ZipLocalFileHeader, (!IsGeneralPurposeBitSet() || (v == 0)), "Invalid CRC");
};
// 7 - compressed size 4 bytes
Field<7>().validation = [&](std::uint32_t& v)
{ ThrowIf(Error::ZipLocalFileHeader, (!IsGeneralPurposeBitSet() || (v == 0)), "Invalid compressed size");
{ ThrowErrorIfNot(Error::ZipLocalFileHeader, (!IsGeneralPurposeBitSet() || (v == 0)), "Invalid compressed size");
};
// 8 - uncompressed size 4 bytes
Field<8>().validation = [&](std::uint32_t& v)
{ ThrowIf(Error::ZipLocalFileHeader, (!IsGeneralPurposeBitSet() || (v == 0)), "Invalid uncompressed size");
{ ThrowErrorIfNot(Error::ZipLocalFileHeader, (!IsGeneralPurposeBitSet() || (v == 0)), "Invalid uncompressed size");
};
// 9 - file name length 2 bytes
Field<9>().validation = [&](std::uint16_t& v)
{ ThrowIf(Error::ZipLocalFileHeader, (v != 0), "unsupported file name size");
{ ThrowErrorIfNot(Error::ZipLocalFileHeader, (v != 0), "unsupported file name size");
Field<11>().value.resize(GetFileNameLength(), 0);
};
// 10- extra field length 2 bytes
Field<10>().validation = [&](std::uint16_t& v)
{ ThrowIf(Error::ZipLocalFileHeader, (v == 0), "unsupported extra field size");
{ ThrowErrorIfNot(Error::ZipLocalFileHeader, (v == 0), "unsupported extra field size");
Field<12>().value.resize(GetExtraFieldLength(), 0);
};
// 11- file name (variable size)
@ -473,7 +473,7 @@ namespace xPlat {
{
// 0 - zip64 end of central dir signature 4 bytes(0x06064b50)
Field<0>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::Zip64EOCDRecord,
{ ThrowErrorIfNot(Error::Zip64EOCDRecord,
(v == static_cast<std::uint32_t>(Signatures::Zip64EndOfCD)),
"end of zip64 central directory does not match signature");
};
@ -482,49 +482,49 @@ namespace xPlat {
{ //4.3.14.1 The value stored into the "size of zip64 end of central
// directory record" should be the size of the remaining
// record and should not include the leading 12 bytes.
ThrowIf(Error::Zip64EOCDRecord, (v == (this->Size() - 12)), "invalid size of zip64 EOCD");
ThrowErrorIfNot(Error::Zip64EOCDRecord, (v == (this->Size() - 12)), "invalid size of zip64 EOCD");
};
// 2 - version made by 2 bytes
Field<2>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::Zip64EOCDRecord,
{ ThrowErrorIfNot(Error::Zip64EOCDRecord,
(v == static_cast<std::uint16_t>(ZipVersions::Zip64FormatExtension)),
"invalid zip64 EOCD version made by");
};
// 3 - version needed to extract 2 bytes
Field<3>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::Zip64EOCDRecord,
{ ThrowErrorIfNot(Error::Zip64EOCDRecord,
(v == static_cast<std::uint16_t>(ZipVersions::Zip64FormatExtension)),
"invalid zip64 EOCD version to extract");
};
// 4 - number of this disk 4 bytes
Field<4>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::Zip64EOCDRecord, (v == 0), "invalid disk number");
{ ThrowErrorIfNot(Error::Zip64EOCDRecord, (v == 0), "invalid disk number");
};
// 5 - number of the disk with the start of the central directory 4 bytes
Field<5>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::Zip64EOCDRecord, (v == 0), "invalid disk index");
{ ThrowErrorIfNot(Error::Zip64EOCDRecord, (v == 0), "invalid disk index");
};
// 6 - total number of entries in the central directory on this disk 8 bytes
Field<6>().validation = [](std::uint64_t& v)
{ ThrowIf(Error::Zip64EOCDRecord, (v != 0), "invalid number of entries");
{ ThrowErrorIfNot(Error::Zip64EOCDRecord, (v != 0), "invalid number of entries");
};
// 7 - total number of entries in the central directory 8 bytes
Field<7>().validation = [&](std::uint64_t& v)
{ ThrowIf(Error::Zip64EOCDRecord, (v == this->GetTotalNumberOfEntries()), "invalid total number of entries");
{ ThrowErrorIfNot(Error::Zip64EOCDRecord, (v == this->GetTotalNumberOfEntries()), "invalid total number of entries");
};
// 8 - size of the central directory 8 bytes
Field<8>().validation = [&](std::uint64_t& v)
{ // TODO: tighten up this validation
ThrowIf(Error::Zip64EOCDRecord, ((v != 0) && (v < m_stream->Ftell())), "invalid size of central directory");
ThrowErrorIfNot(Error::Zip64EOCDRecord, ((v != 0) && (v < m_stream->Ftell())), "invalid size of central directory");
};
// 9 - offset of start of central directory with respect to the starting disk number 8 bytes
Field<9>().validation = [&](std::uint64_t& v)
{ // TODO: tighten up this validation
ThrowIf(Error::Zip64EOCDRecord, ((v != 0) && (v < m_stream->Ftell())), "invalid start of central directory");
ThrowErrorIfNot(Error::Zip64EOCDRecord, ((v != 0) && (v < m_stream->Ftell())), "invalid start of central directory");
};
//10 - zip64 extensible data sector(variable size)
Field<10>().validation = [](std::vector<std::uint8_t>& data)
{ ThrowIf(Error::Zip64EOCDRecord, (data.size() == 0), "unsupported extensible data");
{ ThrowErrorIfNot(Error::Zip64EOCDRecord, (data.size() == 0), "unsupported extensible data");
};
SetSignature(static_cast<std::uint32_t>(Signatures::Zip64EndOfCD));
@ -573,21 +573,21 @@ namespace xPlat {
{
// 0 - zip64 end of central dir locator signature 4 bytes(0x07064b50)
Field<0>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::Zip64EOCDLocator,
{ ThrowErrorIfNot(Error::Zip64EOCDLocator,
(v == static_cast<std::uint32_t>(Signatures::Zip64EndOfCDLocator)),
"end of central directory locator does not match signature");
};
// 1 - number of the disk with the start of the zip64 end of central directory 4 bytes
Field<1>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::Zip64EOCDLocator, (v == 0), "Invalid disk number");
{ ThrowErrorIfNot(Error::Zip64EOCDLocator, (v == 0), "Invalid disk number");
};
// 2 - relative offset of the zip64 end of central directory record 8 bytes
Field<2>().validation = [&](std::uint64_t& v)
{ ThrowIf(Error::Zip64EOCDLocator, ((v != 0) && (v < m_stream->Ftell())), "Invalid relative offset");
{ ThrowErrorIfNot(Error::Zip64EOCDLocator, ((v != 0) && (v < m_stream->Ftell())), "Invalid relative offset");
};
// 3 - total number of disks 4 bytes
Field<3>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::Zip64EOCDLocator, (v == 1), "Invalid total number of disks");
{ ThrowErrorIfNot(Error::Zip64EOCDLocator, (v == 1), "Invalid total number of disks");
};
SetSignature(static_cast<std::uint32_t>(Signatures::Zip64EndOfCDLocator));
@ -627,49 +627,51 @@ namespace xPlat {
{
// 0 - end of central dir signature 4 bytes (0x06054b50)
Field<0>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::ZipEOCDRecord,
{ ThrowErrorIfNot(Error::ZipEOCDRecord,
(v == static_cast<std::uint32_t>(Signatures::EndOfCentralDirectory)),
"invalid signiture");
};
// 1 - number of this disk 2 bytes
Field<1>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipEOCDRecord, (v == 0), "unsupported disk number");
{ ThrowErrorIfNot(Error::ZipEOCDRecord, (v == 0), "unsupported disk number");
// TODO: 0xFFFF -> appxbundle
};
// 2 - number of the disk with the start of the central directory 2 bytes
Field<2>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipEOCDRecord, (v == 0), "unsupported EoCDR disk number");
{ ThrowErrorIfNot(Error::ZipEOCDRecord, (v == 0), "unsupported EoCDR disk number");
// TODO: 0xFFFF -> appxbundle
};
// 3 - total number of entries in the central directory on this disk 2 bytes
Field<3>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipEOCDRecord,
{ ThrowErrorIfNot(Error::ZipEOCDRecord,
(v == std::numeric_limits<std::uint16_t>::max()),
"unsupported total number of entries on this disk");
};
// 4 - total number of entries in the central directory 2 bytes
Field<4>().validation = [](std::uint16_t& v)
{ ThrowIf(Error::ZipEOCDRecord,
{ ThrowErrorIfNot(Error::ZipEOCDRecord,
(v == std::numeric_limits<std::uint16_t>::max()),
"unsupported total number of entries");
};
// 5 - size of the central directory 4 bytes
Field<5>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::ZipEOCDRecord,
{ ThrowErrorIfNot(Error::ZipEOCDRecord,
(v == std::numeric_limits<std::uint32_t>::max()),
"unsupported size of central directory");
};
// 6 - offset of start of central directory with respect to the starting disk number 4 bytes
Field<6>().validation = [](std::uint32_t& v)
{ ThrowIf(Error::ZipEOCDRecord,
{ ThrowErrorIfNot(Error::ZipEOCDRecord,
(v == std::numeric_limits<std::uint32_t>::max()),
"unsupported offset of start of central directory");
};
// 7 - .ZIP file comment length 2 bytes
Field<7>().validation = [&](std::uint16_t& v)
{ ThrowIf(Error::ZipEOCDRecord, (v == 0), "Zip comment unsupported");
{ ThrowErrorIfNot(Error::ZipEOCDRecord, (v == 0), "Zip comment unsupported");
};
// 8 - .ZIP file comment (variable size)
Field<8>().validation = [](std::vector<std::uint8_t>& data)
{ ThrowIf(Error::ZipEOCDRecord, (data.size() == 0), "Zip comment unsupported");
{ ThrowErrorIfNot(Error::ZipEOCDRecord, (data.size() == 0), "Zip comment unsupported");
};
SetSignature(static_cast<std::uint32_t>(Signatures::EndOfCentralDirectory));
@ -757,7 +759,7 @@ namespace xPlat {
}
// We should have no data between the end of the last central directory header and the start of the EoCD
ThrowIf(Error::ZipHiddenData, (m_stream->Ftell() == zip64Locator.GetRelativeOffset()), "hidden data unsupported");
ThrowErrorIfNot(Error::ZipHiddenData, (m_stream->Ftell() == zip64Locator.GetRelativeOffset()), "hidden data unsupported");
// TODO: change to uint64_t when adding full zip64 support
std::map<std::uint32_t, std::shared_ptr<LocalFileHeader>> fileRepository;

Просмотреть файл

@ -37,7 +37,7 @@ unsigned int ResultOf(char* source, char* destination, Lambda lambda)
unsigned int result = 0;
try
{
ThrowIf(xPlat::Error::InvalidParameter, (source != nullptr && destination != nullptr), "Invalid parameters");
ThrowErrorIfNot(xPlat::Error::InvalidParameter, (source != nullptr && destination != nullptr), "Invalid parameters");
lambda();
}
catch (xPlat::Exception& e)