Coverity: tackled a few CIDs (#470)

This commit is contained in:
tomcw
2018-08-12 12:48:08 +01:00
parent 74c0ca2cde
commit 396c55d8a3
4 changed files with 60 additions and 32 deletions
+41 -29
View File
@@ -1214,41 +1214,53 @@ ImageError_e CImageHelperBase::CheckZipFile(LPCTSTR pszImageFilename, ImageInfo*
return eIMAGE_ERROR_UNABLE_TO_OPEN_ZIP;
unz_global_info global_info;
int nRes = unzGetGlobalInfo(hZipFile, &global_info);
if (nRes != UNZ_OK)
return eIMAGE_ERROR_ZIP;
nRes = unzGoToFirstFile(hZipFile); // Only support 1st file in zip archive for now
if (nRes != UNZ_OK)
return eIMAGE_ERROR_ZIP;
unz_file_info file_info;
char szFilename[MAX_PATH];
memset(szFilename, 0, sizeof(szFilename));
nRes = unzGetCurrentFileInfo(hZipFile, &file_info, szFilename, MAX_PATH, NULL, 0, NULL, 0);
if (nRes != UNZ_OK)
return eIMAGE_ERROR_ZIP;
int nRes = 0, nLen = 0;
const UINT uFileSize = file_info.uncompressed_size;
if (uFileSize > GetMaxImageSize())
return eIMAGE_ERROR_BAD_SIZE;
pImageInfo->pImageBuffer = new BYTE[uFileSize];
nRes = unzOpenCurrentFile(hZipFile);
if (nRes != UNZ_OK)
return eIMAGE_ERROR_ZIP;
int nLen = unzReadCurrentFile(hZipFile, pImageInfo->pImageBuffer, uFileSize);
if (nLen < 0)
try
{
unzCloseCurrentFile(hZipFile); // Must CloseCurrentFile before Close
return eIMAGE_ERROR_UNSUPPORTED;
}
nRes = unzGetGlobalInfo(hZipFile, &global_info);
if (nRes != UNZ_OK)
throw eIMAGE_ERROR_ZIP;
nRes = unzCloseCurrentFile(hZipFile);
if (nRes != UNZ_OK)
return eIMAGE_ERROR_ZIP;
nRes = unzGoToFirstFile(hZipFile); // Only support 1st file in zip archive for now
if (nRes != UNZ_OK)
throw eIMAGE_ERROR_ZIP;
nRes = unzGetCurrentFileInfo(hZipFile, &file_info, szFilename, MAX_PATH, NULL, 0, NULL, 0);
if (nRes != UNZ_OK)
throw eIMAGE_ERROR_ZIP;
const UINT uFileSize = file_info.uncompressed_size;
if (uFileSize > GetMaxImageSize())
throw eIMAGE_ERROR_BAD_SIZE;
pImageInfo->pImageBuffer = new BYTE[uFileSize];
nRes = unzOpenCurrentFile(hZipFile);
if (nRes != UNZ_OK)
throw eIMAGE_ERROR_ZIP;
nLen = unzReadCurrentFile(hZipFile, pImageInfo->pImageBuffer, uFileSize);
if (nLen < 0)
{
unzCloseCurrentFile(hZipFile); // Must CloseCurrentFile before Close
throw eIMAGE_ERROR_UNSUPPORTED;
}
nRes = unzCloseCurrentFile(hZipFile);
if (nRes != UNZ_OK)
throw eIMAGE_ERROR_ZIP;
}
catch (ImageError_e error)
{
if (hZipFile)
unzClose(hZipFile);
return error;
}
nRes = unzClose(hZipFile);
hZipFile = NULL;