diff --git a/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp b/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp index a6648dd51e..4b940e3206 100644 --- a/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp +++ b/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp @@ -106,8 +106,20 @@ public: } LPTSTR pszPath; // Retrieves the entire file system path of the file from its shell item - shellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszPath); + HRESULT getDisplayResult = shellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszPath); + if (S_OK != getDisplayResult || nullptr == pszPath) + { + // Avoid crashes in the following code. + return E_FAIL; + } + LPTSTR pszExt = PathFindExtension(pszPath); + if (nullptr == pszExt) + { + CoTaskMemFree(pszPath); + // Avoid crashes in the following code. + return E_FAIL; + } // TODO: Instead, detect whether there's a WIC codec installed that can handle this file AssocGetPerceivedType(pszExt, &type, &flag, NULL); diff --git a/src/modules/imageresizer/dll/ContextMenuHandler.cpp b/src/modules/imageresizer/dll/ContextMenuHandler.cpp index 771479f691..6440b9677b 100644 --- a/src/modules/imageresizer/dll/ContextMenuHandler.cpp +++ b/src/modules/imageresizer/dll/ContextMenuHandler.cpp @@ -82,7 +82,19 @@ HRESULT CContextMenuHandler::QueryContextMenu(_In_ HMENU hmenu, UINT indexMenu, PERCEIVED type; PERCEIVEDFLAG flag; LPTSTR pszPath = i.CurrentItem(); + if (nullptr == pszPath) + { + // Avoid crashes in the following code. + return E_FAIL; + } + LPTSTR pszExt = PathFindExtension(pszPath); + if (nullptr == pszExt) + { + free(pszPath); + // Avoid crashes in the following code. + return E_FAIL; + } // TODO: Instead, detect whether there's a WIC codec installed that can handle this file AssocGetPerceivedType(pszExt, &type, &flag, NULL); @@ -378,8 +390,20 @@ HRESULT __stdcall CContextMenuHandler::GetState(IShellItemArray* psiItemArray, B psiItemArray->GetItemAt(0, &shellItem); LPTSTR pszPath; // Retrieves the entire file system path of the file from its shell item - shellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszPath); + HRESULT getDisplayResult = shellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszPath); + if (S_OK != getDisplayResult || nullptr == pszPath) + { + // Avoid crashes in the following code. + return E_FAIL; + } + LPTSTR pszExt = PathFindExtension(pszPath); + if (nullptr == pszExt) + { + CoTaskMemFree(pszPath); + // Avoid crashes in the following code. + return E_FAIL; + } // TODO: Instead, detect whether there's a WIC codec installed that can handle this file AssocGetPerceivedType(pszExt, &type, &flag, NULL);