[ImageResizer]Fix call to AssocGetPerceivedType (#23267)

This commit is contained in:
Jaime Bernardo
2023-01-11 14:13:00 +00:00
committed by GitHub
parent 3a924ab333
commit eb2968de6e
2 changed files with 38 additions and 2 deletions

View File

@@ -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);

View File

@@ -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);