Skip to content

Commit 6d531a9

Browse files
authored
[ImageResizer]Check for files in HDropIterator before processing (#20985)
1 parent 5e955f0 commit 6d531a9

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/common/utils/HDropIterator.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class HDropIterator
77
HDropIterator(IDataObject* pDataObject)
88
{
99
_current = 0;
10+
_listCount = 0;
1011

1112
FORMATETC formatetc = {
1213
CF_HDROP,
@@ -16,14 +17,22 @@ class HDropIterator
1617
TYMED_HGLOBAL
1718
};
1819

19-
pDataObject->GetData(&formatetc, &m_medium);
20-
21-
_listCount = DragQueryFile((HDROP)m_medium.hGlobal, 0xFFFFFFFF, NULL, 0);
20+
if (SUCCEEDED(pDataObject->GetData(&formatetc, &m_medium)))
21+
{
22+
_listCount = DragQueryFile((HDROP)m_medium.hGlobal, 0xFFFFFFFF, NULL, 0);
23+
}
24+
else
25+
{
26+
m_medium = {};
27+
}
2228
}
2329

2430
~HDropIterator()
2531
{
26-
ReleaseStgMedium(&m_medium);
32+
if (m_medium.tymed)
33+
{
34+
ReleaseStgMedium(&m_medium);
35+
}
2736
}
2837

2938
void First()

src/modules/imageresizer/dll/ContextMenuHandler.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ HRESULT CContextMenuHandler::QueryContextMenu(_In_ HMENU hmenu, UINT indexMenu,
7272
// NB: We just check the first item. We could iterate through more if the first one doesn't meet the criteria
7373
HDropIterator i(m_pdtobj);
7474
i.First();
75+
if (i.IsDone())
76+
{
77+
return S_OK;
78+
}
79+
7580
// Suppressing C26812 warning as the issue is in the shtypes.h library
7681
#pragma warning(suppress : 26812)
7782
PERCEIVED type;

0 commit comments

Comments
 (0)