diff --git a/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp b/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp index d818188c6a..a6648dd51e 100644 --- a/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp +++ b/src/modules/imageresizer/ImageResizerContextMenu/dllmain.cpp @@ -79,6 +79,12 @@ public: IFACEMETHODIMP GetState(_In_opt_ IShellItemArray* selection, _In_ BOOL okToBeSlow, _Out_ EXPCMDSTATE* cmdState) { + if (nullptr == selection) { + // 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. + *cmdState = ECS_HIDDEN; + return S_OK; + } + if (!CSettingsInstance().GetEnabled()) { *cmdState = ECS_HIDDEN; @@ -90,9 +96,14 @@ public: #pragma warning(suppress : 26812) PERCEIVED type; PERCEIVEDFLAG flag; - IShellItem* shellItem; + IShellItem* shellItem=nullptr; //Check extension of first item in the list (the item which is right-clicked on) - selection->GetItemAt(0, &shellItem); + HRESULT getItemResult = selection->GetItemAt(0, &shellItem); + if (S_OK != getItemResult || nullptr == shellItem) { + // Some safeguards to avoid runtime errors. + *cmdState = ECS_HIDDEN; + return S_OK; + } LPTSTR pszPath; // Retrieves the entire file system path of the file from its shell item shellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);