This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +6
-3
lines changed
src/System.Private.CoreLib/shared/System Expand file tree Collapse file tree 3 files changed +6
-3
lines changed Original file line number Diff line number Diff line change 2
2
<Project >
3
3
<PropertyGroup >
4
4
<!-- The .NET Core product branding version -->
5
- <ProductVersion >3.1.5 </ProductVersion >
5
+ <ProductVersion >3.1.6 </ProductVersion >
6
6
<!-- File version numbers -->
7
7
<MajorVersion >4</MajorVersion >
8
8
<MinorVersion >7</MinorVersion >
Original file line number Diff line number Diff line change @@ -323,9 +323,12 @@ public virtual string ReadString()
323
323
return new string ( _charBuffer , 0 , charsRead ) ;
324
324
}
325
325
326
+ // Since we could be reading from an untrusted data source, limit the initial size of the
327
+ // StringBuilder instance we're about to get or create. It'll expand automatically as needed.
328
+
326
329
if ( sb == null )
327
330
{
328
- sb = StringBuilderCache . Acquire ( stringLength ) ; // Actual string length in chars may be smaller.
331
+ sb = StringBuilderCache . Acquire ( Math . Min ( stringLength , StringBuilderCache . MaxBuilderSize ) ) ; // Actual string length in chars may be smaller.
329
332
}
330
333
331
334
sb . Append ( _charBuffer , 0 , charsRead ) ;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ internal static class StringBuilderCache
11
11
// The value 360 was chosen in discussion with performance experts as a compromise between using
12
12
// as litle memory per thread as possible and still covering a large part of short-lived
13
13
// StringBuilder creations on the startup path of VS designers.
14
- private const int MaxBuilderSize = 360 ;
14
+ internal const int MaxBuilderSize = 360 ;
15
15
private const int DefaultCapacity = 16 ; // == StringBuilder.DefaultCapacity
16
16
17
17
// WARNING: We allow diagnostic tools to directly inspect this member (t_cachedInstance).
You can’t perform that action at this time.
0 commit comments