[ZIPFLDR] Fix off-by-one count error during enumeration (#6040)

CORE-19342
This commit is contained in:
Whindmar Saksit 2023-11-26 13:41:02 +01:00 committed by GitHub
parent af7defb556
commit c7777f5963
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,22 +37,35 @@ public:
if (!rgelt || (!pceltFetched && celt != 1))
return E_POINTER;
HRESULT hr = S_OK;
ULONG fetched = 0;
LPITEMIDLIST item;
CStringW name;
bool dir;
unz_file_info64 info;
for (ULONG i = 0; i < celt; ++i)
while (fetched < celt)
{
if (pceltFetched)
*pceltFetched = i;
if (!mEnumerator.next_unique(m_Prefix, name, dir, info))
return S_FALSE;
item = _ILCreate(dir ? ZIP_PIDL_DIRECTORY : ZIP_PIDL_FILE, name, info);
if (!item)
return i ? S_FALSE : E_OUTOFMEMORY;
rgelt[i] = item;
if (mEnumerator.next_unique(m_Prefix, name, dir, info))
{
item = _ILCreate(dir ? ZIP_PIDL_DIRECTORY : ZIP_PIDL_FILE, name, info);
if (!item)
{
hr = fetched ? S_FALSE : E_OUTOFMEMORY;
break;
}
rgelt[fetched++] = item;
}
else
{
hr = S_FALSE;
break;
}
}
return S_OK;
if (pceltFetched)
*pceltFetched = fetched;
return hr;
}
STDMETHODIMP Skip(ULONG celt)
{