[SHELL32] Make Recycle Bin PIDL data handling more robust (#7328)
authorWhindmar Saksit <whindsaks@proton.me>
Fri, 11 Oct 2024 21:47:06 +0000 (23:47 +0200)
committerGitHub <noreply@github.com>
Fri, 11 Oct 2024 21:47:06 +0000 (23:47 +0200)
dll/win32/shell32/folders/CRecycleBin.cpp

index 7bcfe96..32f51b3 100644 (file)
@@ -750,15 +750,20 @@ HRESULT WINAPI CRecycleBin::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, LPS
     TRACE("(%p, %p, %d, %p)\n", this, pidl, iColumn, pDetails);
     if (iColumn >= COLUMNS_COUNT)
         return E_FAIL;
-    pDetails->fmt = RecycleBinColumns[iColumn].fmt;
-    pDetails->cxChar = RecycleBinColumns[iColumn].cxChars;
+
     if (pidl == NULL)
+    {
+        pDetails->fmt = RecycleBinColumns[iColumn].fmt;
+        pDetails->cxChar = RecycleBinColumns[iColumn].cxChars;
         return SHSetStrRet(&pDetails->str, RecycleBinColumns[iColumn].column_name_id);
+    }
 
     if (iColumn == COLUMN_NAME)
         return GetDisplayNameOf(pidl, SHGDN_NORMAL, &pDetails->str);
 
     pFileDetails = _ILGetRecycleStruct(pidl);
+    if (!pFileDetails && FAILED_UNEXPECTEDLY(E_INVALIDARG))
+        return E_INVALIDARG;
     switch (iColumn)
     {
         case COLUMN_DATEDEL:
@@ -766,8 +771,16 @@ HRESULT WINAPI CRecycleBin::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, LPS
             break;
         case COLUMN_DELFROM:
             pszBackslash = wcsrchr(pFileDetails->szName, L'\\');
-            Length = (pszBackslash - pFileDetails->szName);
-            memcpy((LPVOID)buffer, pFileDetails->szName, Length * sizeof(WCHAR));
+            if (!pszBackslash)
+            {
+                ERR("Filename '%ls' not a valid path?\n", pFileDetails->szName);
+                Length = 0;
+            }
+            else
+            {
+                Length = (pszBackslash - pFileDetails->szName);
+                memcpy((LPVOID)buffer, pFileDetails->szName, Length * sizeof(WCHAR));
+            }
             buffer[Length] = UNICODE_NULL;
             if (buffer[0] && buffer[1] == L':' && !buffer[2])
             {