Skip to content

Commit

Permalink
[io/watcher] Fix crash in file event watcher functionality on Windows.
Browse files Browse the repository at this point in the history
It is possible to get '-1' bytes reported as available. This change ensures that only positive number of available bytes are being read.

Fixes #40348

Change-Id: I9f76bd7ca725c9e48ae5a9c44a25d3c12a487194
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164340
Reviewed-by: Siva Annamalai <[email protected]>
Commit-Queue: Alexander Aprelev <[email protected]>
  • Loading branch information
aam authored and [email protected] committed Sep 24, 2020
1 parent 7ec28c3 commit 08c3276
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions runtime/bin/file_system_watcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
const intptr_t kEventSize = sizeof(FILE_NOTIFY_INFORMATION);
DirectoryWatchHandle* dir = reinterpret_cast<DirectoryWatchHandle*>(path_id);
intptr_t available = dir->Available();
if (available <= 0) {
return Dart_NewList(0);
}
intptr_t max_count = available / kEventSize + 1;
Dart_Handle events = Dart_NewList(max_count);
uint8_t* buffer = Dart_ScopeAllocate(available);
Expand Down

0 comments on commit 08c3276

Please sign in to comment.