Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SHFileOperation: randomly raises exceptions when deleting files

I am using SHFileOperation() to delete directories from a specific path. It is done in multiple threads and the directory that's deleted is always different.

From time to time, it throws exceptions:

Exception thrown at 0x00007FF8AF5D9D2A (ntdll.dll) in del.exe: 0xC0000008: An invalid handle was specified

and this one:

Exception thrown at 0x00007FF8ACC90A36 (shell32.dll) in del.exe: 0xC0000005: Access violation reading location 0x0000000000000001.

modules:

shell32.dll 00007FF8ACBD0000-00007FF8AE0D8000 
ntdll.dll   00007FF8AF530000-00007FF8AF701000

This is the code:

SHFILEOPSTRUCTW tFileOptions = { 0 };

/* Initialize the file options structure for the deletion process */
tFileOptions.pFrom = pwstrPath;
tFileOptions.wFunc = FO_DELETE;
tFileOptions.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;

/* Execute the deletions with the Shell operation */
iResult = SHFileOperationW(&tFileOptions);
if (0 != iResult)
{
    printf("WTF\n");
    goto lbl_cleanup;
}

SHChangeNotify(SHCNE_RMDIR, SHCNF_PATHW, pwstrPath, NULL);

The pwstrPath has a double null terminator at the end.

What can be the reason for these exceptions?

EDIT

Stack trace:

enter image description here

like image 472
cydan Avatar asked Oct 18 '22 12:10

cydan


1 Answers

from stack trace (even without pdb symbols - with it will be much more better ) visible that exception not inside windows shell itself but in third party product - dragext64.dll (this is not native windows image) wich is implement Copy Hook Handler - i advise uninstall this or disable via registry key

HKEY_CLASSES_ROOT
   Directory
      shellex
         CopyHookHandlers
            MyCopyHandler
               (Default) = {MyCopyHandler CLSID GUID}

and test after this. think exceptions must go away.


also look like some another shell extensions have bugs here - search in google SHELL32_CallFileCopyHooks. for example bug TortoiseGit.dll - note here in stack trace shell32.dll!SHELL32_CallFileCopyHooks()

so all this bugs inside implementation of ICopyHook::CopyCallback method

like image 120
RbMm Avatar answered Oct 21 '22 03:10

RbMm