Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

[mono-2019-02] Guard against attempting to creating out-of-range spans in macOS File… #322

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ private unsafe void ProcessEvents(int numEvents,
// The base FileSystemWatcher does a match check against the relative path before combining with
// the root dir; however, null is special cased to signify the root dir, so check if we should use that.
ReadOnlySpan<char> relativePath = ReadOnlySpan<char>.Empty;
if (!path.Equals(_fullDirectory, StringComparison.OrdinalIgnoreCase))
if (!path.Equals(_fullDirectory, StringComparison.OrdinalIgnoreCase)
&& path.Length >= _fullDirectory.Length
&& _fullDirectory.AsSpan().Equals(path.Slice(_fullDirectory.Length), StringComparison.OrdinalIgnoreCase))
{
// Remove the root directory to get the relative path
relativePath = path.Slice(_fullDirectory.Length);
Expand Down Expand Up @@ -479,9 +481,18 @@ private unsafe void ProcessEvents(int numEvents,
else
{
// Remove the base directory prefix and add the paired event to the list of
// events to skip and notify the user of the rename
ReadOnlySpan<char> newPathRelativeName = events[pairedId].Span.Slice(_fullDirectory.Length);
watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, newPathRelativeName, relativePath);
// events to skip and notify the user of the rename
if (events[pairedId].Span.Length >= _fullDirectory.Length
&& ((ReadOnlySpan<char>) events[pairedId].Span).Equals(_fullDirectory.AsSpan(0, events[pairedId].Span.Length), StringComparison.OrdinalIgnoreCase))
{
ReadOnlySpan<char> newPathRelativeName = events[pairedId].Span.Slice(_fullDirectory.Length);
watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, newPathRelativeName, relativePath);
}
else
{
//if the base directory prefix isn't there, just use the full absolute path
watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, events[pairedId].Span, relativePath);
}

// Create a new list, if necessary, and add the event
if (handledRenameEvents == null)
Expand Down