From 3d2a2656bba2977dd8b9304b8ffdf08dfd686118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 3 Mar 2018 20:04:51 +0100 Subject: [PATCH] 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. --- source/eventcore/drivers/winapi/watchers.d | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/eventcore/drivers/winapi/watchers.d b/source/eventcore/drivers/winapi/watchers.d index 1928bce..b4e9467 100644 --- a/source/eventcore/drivers/winapi/watchers.d +++ b/source/eventcore/drivers/winapi/watchers.d @@ -127,6 +127,14 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers { while (result.length) { assert(result.length >= FILE_NOTIFY_INFORMATION._FileName.offsetof); 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 .. $]; FileChange ch;