Robustness fix for WinAPIEventDriverWatchers.

Under certain (rare) circumstances, the receive buffer contains data from a file instead of the expected FILE_NOTIFY_INFORMATION structure. No signs of handle or buffer reuse could be found, so the cause for this remains unclear. Until the cause can be narrowed down, this keeps the issue visible while avoiding to crash the application.
This commit is contained in:
Sönke Ludwig 2018-03-03 20:04:51 +01:00
parent fbd6927377
commit 3d2a2656bb

View file

@ -127,6 +127,14 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers {
while (result.length) { while (result.length) {
assert(result.length >= FILE_NOTIFY_INFORMATION._FileName.offsetof); assert(result.length >= FILE_NOTIFY_INFORMATION._FileName.offsetof);
auto fni = () @trusted { return cast(FILE_NOTIFY_INFORMATION*)result.ptr; } (); auto fni = () @trusted { return cast(FILE_NOTIFY_INFORMATION*)result.ptr; } ();
if (fni.NextEntryOffset > result.length) {
import std.stdio : stderr;
() @trusted {
try stderr.writeln("ERROR: Invalid directory watcher event received.");
catch (Exception e) {}
} ();
break;
}
result = result[fni.NextEntryOffset .. $]; result = result[fni.NextEntryOffset .. $];
FileChange ch; FileChange ch;