Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit bf36018

Browse files
jkotasdanmoseley
authored andcommitted
Fix unbounded stackalloc in System.IO.FileSystem (#28004)
1 parent ed489f3 commit bf36018

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static string TranslateWin32Expression(string expression)
3434
return "*";
3535

3636
bool modified = false;
37-
Span<char> stackSpace = stackalloc char[expression.Length];
37+
Span<char> stackSpace = stackalloc char[32];
3838
ValueStringBuilder sb = new ValueStringBuilder(stackSpace);
3939
int length = expression.Length;
4040
for (int i = 0; i < length; i++)

src/System.IO.FileSystem/tests/Enumeration/FileSystemNameTests.netcoreapp.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,12 @@ public void TranslateExpression(string expression, string expected)
143143
{
144144
Assert.Equal(expected, FileSystemName.TranslateWin32Expression(expression));
145145
}
146+
147+
[Fact]
148+
public void TranslateVeryLongExpression()
149+
{
150+
string longString = new string('a', 10_000_000);
151+
Assert.Equal(longString, FileSystemName.TranslateWin32Expression(longString));
152+
}
146153
}
147154
}

0 commit comments

Comments
 (0)