mirror of
https://github.com/AppleWin/AppleWin.git
synced 2026-04-20 00:17:16 +00:00
Coverity: tackled a few CIDs (#470)
This commit is contained in:
+41
-29
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user