From d8226c979aee1cede303919ca38f0b571ba87daf Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Wed, 27 Jun 2012 14:08:05 +0200 Subject: [PATCH] Check for empty icon file, and catch all exceptions when trying to load an icon file Based on TortoiseSVn revision 23023. Signed-off-by: Sven Strickroth --- src/Utils/MiscUI/Picture.cpp | 73 +++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/src/Utils/MiscUI/Picture.cpp b/src/Utils/MiscUI/Picture.cpp index eb67f7de5..371fc8d27 100644 --- a/src/Utils/MiscUI/Picture.cpp +++ b/src/Utils/MiscUI/Picture.cpp @@ -30,21 +30,23 @@ #define HIMETRIC_INCH 2540 CPicture::CPicture() + : m_IPicture(NULL) + , m_Height(0) + , m_Weight(0) + , m_Width(0) + , pBitmap(NULL) + , bHaveGDIPlus(false) + , m_ip(InterpolationModeDefault) + , hIcons(NULL) + , lpIcons(NULL) + , nCurrentIcon(0) + , bIsIcon(false) + , bIsTiff(false) + , m_nSize(0) + , m_ColorDepth(0) + , hGlobal(NULL) + , gdiplusToken(NULL) { - m_IPicture = NULL; - m_Height = 0; - m_Weight = 0; - m_Width = 0; - pBitmap = NULL; - bHaveGDIPlus = false; - m_ip = InterpolationModeDefault; - hIcons = NULL; - lpIcons = NULL; - nCurrentIcon = 0; - bIsIcon = false; - bIsTiff = false; - m_nSize = 0; - m_ColorDepth = 0; } CPicture::~CPicture() @@ -191,20 +193,35 @@ bool CPicture::Load(tstring sFilePathName) hFile.CloseHandle(); LPICONDIR lpIconDir = (LPICONDIR)lpIcons; - if (lpIconDir->idCount * sizeof(ICONDIR) <= fileinfo.nFileIndexLow) + if ((lpIconDir->idCount)&&(lpIconDir->idCount * sizeof(ICONDIR) <= fileinfo.nFileIndexLow)) { - nCurrentIcon = 0; - hIcons = new HICON[lpIconDir->idCount]; - m_Width = lpIconDir->idEntries[0].bWidth; - m_Height = lpIconDir->idEntries[0].bHeight; - for (int i=0; iidCount; ++i) + try { - hIcons[i] = (HICON)LoadImage(NULL, sFilePathName.c_str(), IMAGE_ICON, - lpIconDir->idEntries[i].bWidth, - lpIconDir->idEntries[i].bHeight, - LR_LOADFROMFILE); + nCurrentIcon = 0; + hIcons = new HICON[lpIconDir->idCount]; + m_Width = lpIconDir->idEntries[0].bWidth; + m_Height = lpIconDir->idEntries[0].bHeight; + for (int i=0; iidCount; ++i) + { + hIcons[i] = (HICON)LoadImage(NULL, sFilePathName.c_str(), IMAGE_ICON, + lpIconDir->idEntries[i].bWidth, + lpIconDir->idEntries[i].bHeight, + LR_LOADFROMFILE); + } + bResult = true; } - bResult = true; + catch (...) + { + delete [] lpIcons; + lpIcons = NULL; + bResult = false; + } + } + else + { + delete [] lpIcons; + lpIcons = NULL; + bResult = false; } } else @@ -320,13 +337,13 @@ bool CPicture::Load(tstring sFilePathName) m_Height = height; bResult = true; } - else // Failed to lock the destination Bitmap + else // Failed to lock the destination Bitmap { delete pBitmap; pBitmap = NULL; } } - else // Bitmap allocation failed + else // Bitmap allocation failed { delete pBitmap; pBitmap = NULL; @@ -343,7 +360,7 @@ bool CPicture::Load(tstring sFilePathName) } } } - else // GDI+ Unavailable... + else // GDI+ Unavailable... { int nSize = 0; pBitmap = NULL; -- 2.11.4.GIT