dokan-dev / dokany

User mode file system library for windows with FUSE Wrapper
http://dokan-dev.github.io
5.21k stars 661 forks source link

Mirror : File corruption when copying from mounted drive #1244

Closed michelgre closed 1 day ago

michelgre commented 3 weeks ago

Hello

I noticed a problem when using mirror.exe to mount and copy files.

Environment

Check List

Description

I use mirror.exe to mount a SMB share to a drive of my PC. For some files, but not all, the data is corrupted when I copy the file from the mounted drive. The file length is OK and there is no error popup, but the content is partially messed up and replaced with nulls. The actual content varies from one copy to another for the same file. I noticed that for PDF files and for images files, because the viewer complains that the file is corrupt.

If I open the file directly from the mounted drive, there is no error, the content is correct. The corruption occurs only if I copy the file using Windows explorer or CMD copy.

If I copy the file using the UNC path of the shared folder, there is no error.

If I copy the file with Cygwin cp from the mounted drive, there is no error.

I noticed this problem while I was using an older version of Dokan so I upgraded to the latest version but it did not solve it.

Command to mount the disk : "c:\Program Files\Dokan\mirror.exe" /r \QNAP2\Public\Dokan /l Q:\ /s (as administrator).

Attached:

Logs

mirror.log DbgView.log 30141_50_2.pdf Copied.pdf

Thank you.

Liryna commented 3 weeks ago

Hi @michelgre,

Explorer and copy are working the same for all files but since the issue only happens for some type of files, I would tend to believe it is due to a third party software.

michelgre commented 2 weeks ago

Hello

Thank you Liryna.

I tried but it didn't help.

About the file types, I am not sure that it is the reason. I renamed the example pdf file to .txt to make sure that nothing specific happens and I got the same issue. The copied file is corrupt. It's less about file types than about the content, which is strange.

If I open the (actually pdf) txt file directly in a text editor, from the mounted drive, I get the %PDF-1.3 header at the top.

image

If I copy this file locally and then open it, the file is messed, the beginning is actually the middle data, and somewhere in the middle there are nulls to fill the file to its original size. Very strange.

image

This part can be found inside the original file : image

If I delete the copy and copy again, I have a different content: image

I suspected my NAS (QNAP / QTS 5.1) at first but if I copy the same file using the UNC path, there is no problem so the SMB share works.

I also disabled the antivirus program during the test.

It's more like some data inside the file would trigged the incorrect behavior of mirror, like retrieving the wrong data block, and only during a windows copy.

Here is the result of the command:

C:\Windows\System32>fltmc filters

Nom de filtre                   Nom. d’instn.  Altitude      Cadre
------------------------------  -------------  ------------  -----
bindflt                                 1       409800         0
aswSP                                  16       388401         0
aswMonFlt                              16       320700         0
storqosflt                              0       244000         0
wcifs                                   0       189900         0
CldFlt                                  2       180451         0
bfs                                    18       150000         0
FileCrypt                               0       141100         0
aswSnx                                 15       137600         0
luafv                                   1       135000         0
npsvctrig                               1        46000         0
Wof                                     8        40700         0
FileInfo                               16        40500         0

C:\Windows\System32>
Liryna commented 2 weeks ago

I also disabled the antivirus program during the test.

That often not enough to fully disable them. Do you have the possibility to do the test on a clean environment ?

Read and write are well tested and the description of the issue really makes me believe there is a third party corrupting the data. You might be lucky to find which one by using procmon and inspect the read callstack. It could show one of those present in your fltmc filters output

Liryna commented 1 day ago

Please do not hesitate to reopen if you have new information