Closed grandemk closed 1 year ago
Hi @grandemk ,
You are correct. There should be a lock wrapping the SetFilePointerEx
and ReadFile
.
I think using OVERLAPPED instead of SetFilePointerEx is sufficient to solve the issue Something like this:
OVERLAPPED overlap;
memset(&overlap, 0, sizeof(OVERLAPPED));
overlap.Offset = Offset & 0xFFFFFFFF;
overlap.OffsetHigh = (Offset >> 32) & 0xFFFFFFFF;
if (!ReadFile(handle, Buffer, BufferLength, ReadLength, &overlap))
That can work too! Do you mind creating a pull request with the change ? Would be very appreciated
Done with https://github.com/dokan-dev/dokany/commit/f225a0d60a1dc3d3656ccef3c6c99401ac66a20b
Thanks @grandemk for the report and providing the solution!
Environment
Check List
Description
Hi :)
There is a race condition in the ReadFile and in the WriteFile function.
If 2 MirrorReadFile happen at the same time, the following run gives a wrong result: MirrorReadFile 2 calls SetFilePointerEx MirrorReadFile 1 calls SetFilePointerEx MirrorReadFile 2 calls ReadFile and uses the offset of MirrorReadFile 1 MirrorReadFile 1 calls ReadFile and uses the offset set after the text that was read by MirrorReadFile 2.
Here is a program to reproduce the issue: