Skip to content

Commit d300b00

Browse files
[ImageResizer]Fix silent context menu crash (#22503)
1 parent ba9e244 commit d300b00

File tree

1 file changed

+13
-2
lines changed
  • src/modules/imageresizer/ImageResizerContextMenu

1 file changed

+13
-2
lines changed

src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ class __declspec(uuid("8F491918-259F-451A-950F-8C3EBF4864AF")) ImageResizerConte
7979

8080
IFACEMETHODIMP GetState(_In_opt_ IShellItemArray* selection, _In_ BOOL okToBeSlow, _Out_ EXPCMDSTATE* cmdState)
8181
{
82+
if (nullptr == selection) {
83+
// We've observed that it's possible that a null gets passed instead of an empty array. Just don't show the context menu in this case.
84+
*cmdState = ECS_HIDDEN;
85+
return S_OK;
86+
}
87+
8288
if (!CSettingsInstance().GetEnabled())
8389
{
8490
*cmdState = ECS_HIDDEN;
@@ -90,9 +96,14 @@ class __declspec(uuid("8F491918-259F-451A-950F-8C3EBF4864AF")) ImageResizerConte
9096
#pragma warning(suppress : 26812)
9197
PERCEIVED type;
9298
PERCEIVEDFLAG flag;
93-
IShellItem* shellItem;
99+
IShellItem* shellItem=nullptr;
94100
//Check extension of first item in the list (the item which is right-clicked on)
95-
selection->GetItemAt(0, &shellItem);
101+
HRESULT getItemResult = selection->GetItemAt(0, &shellItem);
102+
if (S_OK != getItemResult || nullptr == shellItem) {
103+
// Some safeguards to avoid runtime errors.
104+
*cmdState = ECS_HIDDEN;
105+
return S_OK;
106+
}
96107
LPTSTR pszPath;
97108
// Retrieves the entire file system path of the file from its shell item
98109
shellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);

0 commit comments

Comments
 (0)