Silence analyzer warnings and fix potential issues

This commit is contained in:
vit9696 2018-05-08 18:42:16 +03:00
parent e7ca5715d5
commit 2042d07d72
11 changed files with 85 additions and 73 deletions

7
.gitignore vendored
View File

@ -231,3 +231,10 @@ pip-log.txt
############# #############
*.o *.o
Makefile Makefile
UEFITool/uefitool_plugin_import.cpp
UEFITool.app/
.qmake.stash
CMakeCache.txt
CMakeFiles
cmake_install.cmake

View File

@ -47,8 +47,8 @@ void HexViewDialog::setItem(const UModelIndex & index, bool bodyOnly)
setWindowTitle(UString("Hex view: ") + (itemText.isEmpty() ? itemName : itemName + " | " + itemText)); setWindowTitle(UString("Hex view: ") + (itemText.isEmpty() ? itemName : itemName + " | " + itemText));
// Set hex data // Set hex data
QByteArray data; QByteArray hexdata;
if (bodyOnly) data = model->body(index); if (bodyOnly) hexdata = model->body(index);
else data = model->header(index) + model->body(index) + model->tail(index); else hexdata = model->header(index) + model->body(index) + model->tail(index);
hexView->setData(data); hexView->setData(hexdata);
} }

View File

@ -374,8 +374,8 @@ void UEFITool::goToData()
if (model->hasEmptyParsingData(index)) if (model->hasEmptyParsingData(index))
continue; continue;
UByteArray data = model->parsingData(index); UByteArray rdata = model->parsingData(index);
const NVAR_ENTRY_PARSING_DATA* pdata = (const NVAR_ENTRY_PARSING_DATA*)data.constData(); const NVAR_ENTRY_PARSING_DATA* pdata = (const NVAR_ENTRY_PARSING_DATA*)rdata.constData();
UINT32 lastVariableFlag = pdata->emptyByte ? 0xFFFFFF : 0; UINT32 lastVariableFlag = pdata->emptyByte ? 0xFFFFFF : 0;
UINT32 offset = model->offset(index); UINT32 offset = model->offset(index);
if (pdata->next == lastVariableFlag) { if (pdata->next == lastVariableFlag) {

View File

@ -21,10 +21,6 @@ USTATUS FfsOperations::extract(const UModelIndex & index, UString & name, UByteA
if (!index.isValid()) if (!index.isValid())
return U_INVALID_PARAMETER; return U_INVALID_PARAMETER;
// Construct a name for extracted data
UString itemName = model->name(index);
UString itemText = model->text(index);
// Default name // Default name
name = uniqueItemName(index); name = uniqueItemName(index);
@ -77,10 +73,8 @@ USTATUS FfsOperations::replace(const UModelIndex & index, const UString & data,
else if (mode == REPLACE_MODE_BODY) { else if (mode == REPLACE_MODE_BODY) {
return U_NOT_IMPLEMENTED; return U_NOT_IMPLEMENTED;
} }
else
return U_UNKNOWN_REPLACE_MODE;
return U_NOT_IMPLEMENTED; return U_UNKNOWN_REPLACE_MODE;
} }
USTATUS FfsOperations::remove(const UModelIndex & index) USTATUS FfsOperations::remove(const UModelIndex & index)

View File

@ -1399,6 +1399,7 @@ USTATUS FfsParser::parseFileHeader(const UByteArray & file, const UINT32 localOf
ffsVersion = pdata->ffsVersion; ffsVersion = pdata->ffsVersion;
volumeAlignment = pdata->alignment; volumeAlignment = pdata->alignment;
volumeRevision = pdata->revision; volumeRevision = pdata->revision;
isWeakAligned = pdata->isWeakAligned;
} }
// Get file header // Get file header
@ -2933,13 +2934,13 @@ USTATUS FfsParser::addMemoryAddressesRecursive(const UModelIndex & index)
// Determine relocation type of uncompressed TE image sections // Determine relocation type of uncompressed TE image sections
if (model->type(index) == Types::Section && model->subtype(index) == EFI_SECTION_TE) { if (model->type(index) == Types::Section && model->subtype(index) == EFI_SECTION_TE) {
// Obtain required values from parsing data // Obtain required values from parsing data
UINT32 imageBase = 0; UINT32 originalImageBase = 0;
UINT32 adjustedImageBase = 0; UINT32 adjustedImageBase = 0;
UINT8 imageBaseType = EFI_IMAGE_TE_BASE_OTHER; UINT8 imageBaseType = EFI_IMAGE_TE_BASE_OTHER;
if (model->hasEmptyParsingData(index) == false) { if (model->hasEmptyParsingData(index) == false) {
UByteArray data = model->parsingData(index); UByteArray data = model->parsingData(index);
const TE_IMAGE_SECTION_PARSING_DATA* pdata = (const TE_IMAGE_SECTION_PARSING_DATA*)data.constData(); const TE_IMAGE_SECTION_PARSING_DATA* pdata = (const TE_IMAGE_SECTION_PARSING_DATA*)data.constData();
imageBase = pdata->imageBase; originalImageBase = pdata->imageBase;
adjustedImageBase = pdata->adjustedImageBase; adjustedImageBase = pdata->adjustedImageBase;
} }
@ -2974,7 +2975,7 @@ USTATUS FfsParser::addMemoryAddressesRecursive(const UModelIndex & index)
// Update parsing data // Update parsing data
TE_IMAGE_SECTION_PARSING_DATA pdata; TE_IMAGE_SECTION_PARSING_DATA pdata;
pdata.imageBaseType = imageBaseType; pdata.imageBaseType = imageBaseType;
pdata.imageBase = imageBase; pdata.imageBase = originalImageBase;
pdata.adjustedImageBase = adjustedImageBase; pdata.adjustedImageBase = adjustedImageBase;
model->setParsingData(index, UByteArray((const char*)&pdata, sizeof(pdata))); model->setParsingData(index, UByteArray((const char*)&pdata, sizeof(pdata)));
} }
@ -3246,8 +3247,8 @@ USTATUS FfsParser::parseVendorHashFile(const UByteArray & fileGuid, const UModel
for (UINT32 i = 0; i < header->NumEntries; i++) { for (UINT32 i = 0; i < header->NumEntries; i++) {
const BG_VENDOR_HASH_FILE_ENTRY* entry = (const BG_VENDOR_HASH_FILE_ENTRY*)(header + 1) + i; const BG_VENDOR_HASH_FILE_ENTRY* entry = (const BG_VENDOR_HASH_FILE_ENTRY*)(header + 1) + i;
bootGuardInfo += usprintf("\nRelativeOffset: %08Xh Size: %Xh\nHash: ", entry->Offset, entry->Size); bootGuardInfo += usprintf("\nRelativeOffset: %08Xh Size: %Xh\nHash: ", entry->Offset, entry->Size);
for (UINT8 i = 0; i < sizeof(entry->Hash); i++) { for (UINT8 j = 0; j < sizeof(entry->Hash); j++) {
bootGuardInfo += usprintf("%02X", entry->Hash[i]); bootGuardInfo += usprintf("%02X", entry->Hash[j]);
} }
} }
bootGuardInfo += UString("\n------------------------------------------------------------------------\n\n"); bootGuardInfo += UString("\n------------------------------------------------------------------------\n\n");
@ -3285,8 +3286,8 @@ USTATUS FfsParser::parseVendorHashFile(const UByteArray & fileGuid, const UModel
for (UINT32 i = 0; i < NumEntries; i++) { for (UINT32 i = 0; i < NumEntries; i++) {
const BG_VENDOR_HASH_FILE_ENTRY* entry = (const BG_VENDOR_HASH_FILE_ENTRY*)(model->body(index).constData()) + i; const BG_VENDOR_HASH_FILE_ENTRY* entry = (const BG_VENDOR_HASH_FILE_ENTRY*)(model->body(index).constData()) + i;
bootGuardInfo += usprintf("\nAddress: %08Xh Size: %Xh\nHash: ", entry->Offset, entry->Size); bootGuardInfo += usprintf("\nAddress: %08Xh Size: %Xh\nHash: ", entry->Offset, entry->Size);
for (UINT8 i = 0; i < sizeof(entry->Hash); i++) { for (UINT8 j = 0; j < sizeof(entry->Hash); j++) {
bootGuardInfo += usprintf("%02X", entry->Hash[i]); bootGuardInfo += usprintf("%02X", entry->Hash[j]);
} }
} }
bootGuardInfo += UString("\n------------------------------------------------------------------------\n\n"); bootGuardInfo += UString("\n------------------------------------------------------------------------\n\n");
@ -3385,7 +3386,7 @@ USTATUS FfsParser::parseFit(const UModelIndex & index)
currentStrings.push_back(usprintf("%04Xh", fitHeader->Version)); currentStrings.push_back(usprintf("%04Xh", fitHeader->Version));
currentStrings.push_back(usprintf("%02Xh", fitHeader->Checksum)); currentStrings.push_back(usprintf("%02Xh", fitHeader->Checksum));
currentStrings.push_back(fitEntryTypeToUString(fitHeader->Type)); currentStrings.push_back(fitEntryTypeToUString(fitHeader->Type));
currentStrings.push_back(UString("")); // Empty info for FIT header currentStrings.push_back(UString()); // Empty info for FIT header
fitTable.push_back(std::pair<std::vector<UString>, UModelIndex>(currentStrings, fitIndex)); fitTable.push_back(std::pair<std::vector<UString>, UModelIndex>(currentStrings, fitIndex));
// Process all other entries // Process all other entries
@ -3844,13 +3845,13 @@ USTATUS FfsParser::parseIntelBootGuardBootPolicy(const UByteArray & bootPolicy,
elementHeader->DataSize elementHeader->DataSize
); );
// Check for Microsoft PMDA hash data // Check for Microsoft PMDA hash data
const BG_MICROSOFT_PMDA_HEADER* header = (const BG_MICROSOFT_PMDA_HEADER*)(elementHeader + 1); const BG_MICROSOFT_PMDA_HEADER* pmdaHeader = (const BG_MICROSOFT_PMDA_HEADER*)(elementHeader + 1);
if (header->Version == BG_MICROSOFT_PMDA_VERSION if (pmdaHeader->Version == BG_MICROSOFT_PMDA_VERSION
&& elementHeader->DataSize == sizeof(BG_MICROSOFT_PMDA_HEADER) + sizeof(BG_MICROSOFT_PMDA_ENTRY)*header->NumEntries) { && elementHeader->DataSize == sizeof(BG_MICROSOFT_PMDA_HEADER) + sizeof(BG_MICROSOFT_PMDA_ENTRY)*pmdaHeader->NumEntries) {
// Add entries // Add entries
bootGuardInfo += UString("\nMicrosoft PMDA-based protected ranges:\n"); bootGuardInfo += UString("\nMicrosoft PMDA-based protected ranges:\n");
const BG_MICROSOFT_PMDA_ENTRY* entries = (const BG_MICROSOFT_PMDA_ENTRY*)(header + 1); const BG_MICROSOFT_PMDA_ENTRY* entries = (const BG_MICROSOFT_PMDA_ENTRY*)(pmdaHeader + 1);
for (UINT32 i = 0; i < header->NumEntries; i++) { for (UINT32 i = 0; i < pmdaHeader->NumEntries; i++) {
bootGuardInfo += usprintf("Address: %08Xh Size: %08Xh\n", entries[i].Address, entries[i].Size); bootGuardInfo += usprintf("Address: %08Xh Size: %08Xh\n", entries[i].Address, entries[i].Size);
bootGuardInfo += UString("Hash: "); bootGuardInfo += UString("Hash: ");

View File

@ -66,7 +66,7 @@ public:
private: private:
TreeModel *model; TreeModel *model;
std::vector<std::pair<UString, UModelIndex> > messagesVector; std::vector<std::pair<UString, UModelIndex> > messagesVector;
void msg(const UString message, const UModelIndex index = UModelIndex()) { void msg(const UString & message, const UModelIndex & index = UModelIndex()) {
messagesVector.push_back(std::pair<UString, UModelIndex>(message, index)); messagesVector.push_back(std::pair<UString, UModelIndex>(message, index));
}; };

View File

@ -937,18 +937,9 @@ USTATUS NvramParser::parseFdcStoreHeader(const UByteArray & store, const UINT32
return U_SUCCESS; return U_SUCCESS;
} }
// Check header size
UINT32 headerSize = sizeof(FDC_VOLUME_HEADER);
if (dataSize < headerSize) {
msg(usprintf("%s: FDC store header size %Xh (%u) is greater than volume body size %Xh (%u)", __FUNCTION__,
fdcStoreHeader->Size, fdcStoreHeader->Size,
dataSize, dataSize), parent);
return U_SUCCESS;
}
// Construct header and body // Construct header and body
UByteArray header = store.left(headerSize); UByteArray header = store.left(sizeof(FDC_VOLUME_HEADER));
UByteArray body = store.mid(headerSize, fdcStoreHeader->Size - headerSize); UByteArray body = store.mid(sizeof(FDC_VOLUME_HEADER), fdcStoreHeader->Size - sizeof(FDC_VOLUME_HEADER));
// Add info // Add info
UString name("FDC store"); UString name("FDC store");
@ -1391,7 +1382,7 @@ USTATUS NvramParser::parseVssStoreBody(const UModelIndex & index, UINT8 alignmen
// Parse all variables // Parse all variables
while (1) { while (1) {
bool isInvalid = false; bool isInvalid = true;
bool isAuthenticated = false; bool isAuthenticated = false;
bool isAppleCrc32 = false; bool isAppleCrc32 = false;
bool isIntelSpecial = false; bool isIntelSpecial = false;
@ -1465,7 +1456,8 @@ USTATUS NvramParser::parseVssStoreBody(const UModelIndex & index, UINT8 alignmen
} }
// Intel special variable // Intel special variable
else if (variableHeader->State == NVRAM_VSS_INTEL_VARIABLE_VALID || variableHeader->State == NVRAM_VSS_INTEL_VARIABLE_INVALID) { else if (variableHeader->State == NVRAM_VSS_INTEL_VARIABLE_VALID
|| variableHeader->State == NVRAM_VSS_INTEL_VARIABLE_INVALID) {
isIntelSpecial = true; isIntelSpecial = true;
const VSS_INTEL_VARIABLE_HEADER* intelVariableHeader = (const VSS_INTEL_VARIABLE_HEADER*)variableHeader; const VSS_INTEL_VARIABLE_HEADER* intelVariableHeader = (const VSS_INTEL_VARIABLE_HEADER*)variableHeader;
variableSize = intelVariableHeader->TotalSize; variableSize = intelVariableHeader->TotalSize;
@ -1483,7 +1475,7 @@ USTATUS NvramParser::parseVssStoreBody(const UModelIndex & index, UINT8 alignmen
} }
// Normal VSS variable // Normal VSS variable
if (!isAuthenticated && !isAppleCrc32 && !isIntelSpecial) { else {
variableSize = sizeof(VSS_VARIABLE_HEADER) + variableHeader->NameSize + variableHeader->DataSize; variableSize = sizeof(VSS_VARIABLE_HEADER) + variableHeader->NameSize + variableHeader->DataSize;
variableGuid = (EFI_GUID*)&variableHeader->VendorGuid; variableGuid = (EFI_GUID*)&variableHeader->VendorGuid;
variableName = (CHAR16*)(variableHeader + 1); variableName = (CHAR16*)(variableHeader + 1);
@ -1493,8 +1485,10 @@ USTATUS NvramParser::parseVssStoreBody(const UModelIndex & index, UINT8 alignmen
} }
// Check variable state // Check variable state
if (variableHeader->State != NVRAM_VSS_INTEL_VARIABLE_VALID && variableHeader->State != NVRAM_VSS_VARIABLE_ADDED && variableHeader->State != NVRAM_VSS_VARIABLE_HEADER_VALID) { if (variableHeader->State == NVRAM_VSS_INTEL_VARIABLE_VALID
isInvalid = true; || variableHeader->State == NVRAM_VSS_VARIABLE_ADDED
|| variableHeader->State == NVRAM_VSS_VARIABLE_HEADER_VALID) {
isInvalid = false;
} }
// Check variable size // Check variable size
@ -1565,8 +1559,9 @@ USTATUS NvramParser::parseVssStoreBody(const UModelIndex & index, UINT8 alignmen
else if (isIntelSpecial) { else if (isIntelSpecial) {
subtype = Subtypes::IntelVssEntry; subtype = Subtypes::IntelVssEntry;
} }
else else {
subtype = Subtypes::StandardVssEntry; subtype = Subtypes::StandardVssEntry;
}
// Add tree item // Add tree item
model->addItem(localOffset + offset, Types::VssEntry, subtype, name, text, info, header, body, UByteArray(), Movable, index); model->addItem(localOffset + offset, Types::VssEntry, subtype, name, text, info, header, body, UByteArray(), Movable, index);
@ -1596,12 +1591,12 @@ USTATUS NvramParser::parseFsysStoreBody(const UModelIndex & index)
const UByteArray data = model->body(index); const UByteArray data = model->body(index);
// Check that the is enough space for variable header // Check that the is enough space for variable header
const UINT32 dataSize = (UINT32)data.size(); const UINT32 storeDataSize = (UINT32)data.size();
UINT32 offset = 0; UINT32 offset = 0;
// Parse all variables // Parse all variables
while (1) { while (1) {
UINT32 unparsedSize = dataSize - offset; UINT32 unparsedSize = storeDataSize - offset;
UINT32 variableSize = 0; UINT32 variableSize = 0;
// Get nameSize and name of the variable // Get nameSize and name of the variable
@ -1699,14 +1694,14 @@ USTATUS NvramParser::parseEvsaStoreBody(const UModelIndex & index)
const UByteArray data = model->body(index); const UByteArray data = model->body(index);
// Check that the is enough space for entry header // Check that the is enough space for entry header
const UINT32 dataSize = (UINT32)data.size(); const UINT32 storeDataSize = (UINT32)data.size();
UINT32 offset = 0; UINT32 offset = 0;
std::map<UINT16, EFI_GUID> guidMap; std::map<UINT16, EFI_GUID> guidMap;
std::map<UINT16, UString> nameMap; std::map<UINT16, UString> nameMap;
// Parse all entries // Parse all entries
UINT32 unparsedSize = dataSize; UINT32 unparsedSize = storeDataSize;
while (unparsedSize) { while (unparsedSize) {
UINT32 variableSize = 0; UINT32 variableSize = 0;
UString name; UString name;
@ -1721,8 +1716,8 @@ USTATUS NvramParser::parseEvsaStoreBody(const UModelIndex & index)
// Check entry size // Check entry size
variableSize = sizeof(EVSA_ENTRY_HEADER); variableSize = sizeof(EVSA_ENTRY_HEADER);
if (unparsedSize < variableSize || unparsedSize < entryHeader->Size) { if (unparsedSize < variableSize || unparsedSize < entryHeader->Size) {
UByteArray body = data.mid(offset); body = data.mid(offset);
UString info = usprintf("Full size: %Xh (%u)", body.size(), body.size()); info = usprintf("Full size: %Xh (%u)", body.size(), body.size());
if (body.count(emptyByte) == body.size()) { // Free space if (body.count(emptyByte) == body.size()) { // Free space
// Add free space tree item // Add free space tree item
@ -1813,8 +1808,8 @@ USTATUS NvramParser::parseEvsaStoreBody(const UModelIndex & index)
} }
// Unknown entry or free space // Unknown entry or free space
else { else {
UByteArray body = data.mid(offset); body = data.mid(offset);
UString info = usprintf("Full size: %Xh (%u)", body.size(), body.size()); info = usprintf("Full size: %Xh (%u)", body.size(), body.size());
if (body.count(emptyByte) == body.size()) { // Free space if (body.count(emptyByte) == body.size()) { // Free space
// Add free space tree item // Add free space tree item
@ -1835,7 +1830,7 @@ USTATUS NvramParser::parseEvsaStoreBody(const UModelIndex & index)
// Move to next variable // Move to next variable
offset += variableSize; offset += variableSize;
unparsedSize = dataSize - offset; unparsedSize = storeDataSize - offset;
} }
// Reparse all data variables to detect invalid ones and assign name and test to valid ones // Reparse all data variables to detect invalid ones and assign name and test to valid ones

View File

@ -44,7 +44,7 @@ private:
TreeModel *model; TreeModel *model;
FfsParser *ffsParser; FfsParser *ffsParser;
std::vector<std::pair<UString, UModelIndex> > messagesVector; std::vector<std::pair<UString, UModelIndex> > messagesVector;
void msg(const UString message, const UModelIndex index = UModelIndex()) { void msg(const UString & message, const UModelIndex & index = UModelIndex()) {
messagesVector.push_back(std::pair<UString, UModelIndex>(message, index)); messagesVector.push_back(std::pair<UString, UModelIndex>(message, index));
}; };

View File

@ -20,16 +20,16 @@ routines without the need of backward traversal
#include "basetypes.h" #include "basetypes.h"
typedef struct VOLUME_PARSING_DATA_ { typedef struct VOLUME_PARSING_DATA_ {
UINT8 ffsVersion;
UINT8 emptyByte;
EFI_GUID extendedHeaderGuid; EFI_GUID extendedHeaderGuid;
UINT32 alignment; UINT32 alignment;
UINT32 usedSpace;
BOOLEAN hasValidUsedSpace;
UINT8 ffsVersion;
UINT8 emptyByte;
UINT8 revision; UINT8 revision;
BOOLEAN hasExtendedHeader; BOOLEAN hasExtendedHeader;
BOOLEAN hasAppleCrc32; BOOLEAN hasAppleCrc32;
BOOLEAN isWeakAligned; BOOLEAN isWeakAligned;
BOOLEAN hasValidUsedSpace;
UINT32 usedSpace;
} VOLUME_PARSING_DATA; } VOLUME_PARSING_DATA;
typedef struct FILE_PARSING_DATA_ { typedef struct FILE_PARSING_DATA_ {

View File

@ -586,8 +586,8 @@ typedef struct {
} EFI_IMAGE_THUNK_DATA; } EFI_IMAGE_THUNK_DATA;
#define EFI_IMAGE_ORDINAL_FLAG 0x80000000 // Flag for PE32. #define EFI_IMAGE_ORDINAL_FLAG 0x80000000 // Flag for PE32.
#define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0) #define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) (((Ordinal) & EFI_IMAGE_ORDINAL_FLAG) != 0)
#define EFI_IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff) #define EFI_IMAGE_ORDINAL(Ordinal) ((Ordinal) & 0xffff)
// //
// Import Directory Table // Import Directory Table

View File

@ -235,18 +235,25 @@ USTATUS decompress(const UByteArray & compressedData, const UINT8 compressionTyp
// Try EFI 1.1 // Try EFI 1.1
USTATUS EfiResult = EfiDecompress(data, dataSize, efiDecompressed, decompressedSize, scratch, scratchSize); USTATUS EfiResult = EfiDecompress(data, dataSize, efiDecompressed, decompressedSize, scratch, scratchSize);
if (decompressedSize > INT32_MAX) {
free(decompressed);
free(efiDecompressed);
free(scratch);
return U_STANDARD_DECOMPRESSION_FAILED;
}
if (EfiResult == U_SUCCESS && TianoResult == U_SUCCESS) { // Both decompressions are OK if (EfiResult == U_SUCCESS && TianoResult == U_SUCCESS) { // Both decompressions are OK
algorithm = COMPRESSION_ALGORITHM_UNDECIDED; algorithm = COMPRESSION_ALGORITHM_UNDECIDED;
decompressedData = UByteArray((const char*)decompressed, decompressedSize); decompressedData = UByteArray((const char*)decompressed, (int)decompressedSize);
efiDecompressedData = UByteArray((const char*)efiDecompressed, decompressedSize); efiDecompressedData = UByteArray((const char*)efiDecompressed, (int)decompressedSize);
} }
else if (TianoResult == U_SUCCESS) { // Only Tiano is OK else if (TianoResult == U_SUCCESS) { // Only Tiano is OK
algorithm = COMPRESSION_ALGORITHM_TIANO; algorithm = COMPRESSION_ALGORITHM_TIANO;
decompressedData = UByteArray((const char*)decompressed, decompressedSize); decompressedData = UByteArray((const char*)decompressed, (int)decompressedSize);
} }
else if (EfiResult == U_SUCCESS) { // Only EFI 1.1 is OK else if (EfiResult == U_SUCCESS) { // Only EFI 1.1 is OK
algorithm = COMPRESSION_ALGORITHM_EFI11; algorithm = COMPRESSION_ALGORITHM_EFI11;
decompressedData = UByteArray((const char*)efiDecompressed, decompressedSize); decompressedData = UByteArray((const char*)efiDecompressed, (int)decompressedSize);
} }
else { // Both decompressions failed else { // Both decompressions failed
result = U_STANDARD_DECOMPRESSION_FAILED; result = U_STANDARD_DECOMPRESSION_FAILED;
@ -293,13 +300,21 @@ USTATUS decompress(const UByteArray & compressedData, const UINT8 compressionTyp
return U_CUSTOMIZED_DECOMPRESSION_FAILED; return U_CUSTOMIZED_DECOMPRESSION_FAILED;
} }
else { else {
if (decompressedSize > INT32_MAX) {
free(decompressed);
return U_CUSTOMIZED_DECOMPRESSION_FAILED;
}
algorithm = COMPRESSION_ALGORITHM_IMLZMA; algorithm = COMPRESSION_ALGORITHM_IMLZMA;
decompressedData = UByteArray((const char*)decompressed, decompressedSize); decompressedData = UByteArray((const char*)decompressed, (int)decompressedSize);
} }
} }
else { else {
if (decompressedSize > INT32_MAX) {
free(decompressed);
return U_CUSTOMIZED_DECOMPRESSION_FAILED;
}
algorithm = COMPRESSION_ALGORITHM_LZMA; algorithm = COMPRESSION_ALGORITHM_LZMA;
decompressedData = UByteArray((const char*)decompressed, decompressedSize); decompressedData = UByteArray((const char*)decompressed, (int)decompressedSize);
} }
free(decompressed); free(decompressed);
@ -330,7 +345,7 @@ UINT8 calculateChecksum8(const UINT8* buffer, UINT32 bufferSize)
if (!buffer) if (!buffer)
return 0; return 0;
return (UINT8)0x100 - calculateSum8(buffer, bufferSize); return (UINT8)(0x100U - calculateSum8(buffer, bufferSize));
} }
// 16bit checksum calculation routine // 16bit checksum calculation routine