Skip to content

Commit eb91e30

Browse files
committed
Add missing lock around files variable
The files dictionary could be modified and resized by another thread. Without the lock, the read is not synchronized and can cause a KeyNotFoundException.
1 parent 79fafd0 commit eb91e30

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ private string GetPathWithCorrectDirectoryCapitalization(string fullPath)
156156

157157
if (DirectoryExistsWithoutFixingPath(leftHalf))
158158
{
159-
string baseDirectory = files[leftHalf].Path;
159+
string baseDirectory;
160+
lock (files)
161+
{
162+
baseDirectory = files[leftHalf].Path;
163+
}
164+
160165
return baseDirectory + Path.DirectorySeparatorChar + rightHalf;
161166
}
162167
}
@@ -581,4 +586,4 @@ private class FileSystemEntry
581586
public string Path { get; set; }
582587
public MockFileData Data { get; set; }
583588
}
584-
}
589+
}

0 commit comments

Comments
 (0)