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

Commit 9299d90

Browse files
GrabYourPitchforkswtgodbe
authored andcommitted
Tighten bounds checks around TextEncoder logic
- Replaces unsafe code with safe code where possible - Fixes some surrogate pairs being misinterpreted - Fixes dotnet/runtime#45994 - Ref: MSRC 62749 (CVE-2021-26701)
1 parent 055deb1 commit 9299d90

22 files changed

+720
-531
lines changed

NuGet.config

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<add key="dotnet3.1-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1-transport/nuget/v3/index.json" />
1515
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
1616
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
17+
<!-- Harvesting feed from 2.1 -->
18+
<add key="darc-int-corefx-2.1.26" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-corefx-2.1.26/nuget/v3/index.json" />
1719
</packageSources>
1820
<disabledPackageSources>
1921
<clear />

pkg/Microsoft.Private.PackageBaseline/packageIndex.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -5554,23 +5554,26 @@
55545554
"4.3.1",
55555555
"4.4.0",
55565556
"4.5.0",
5557-
"4.6.0",
5557+
"4.5.1",
55585558
"4.7.0",
5559-
"4.7.1"
5559+
"4.7.1",
5560+
"4.7.2"
55605561
],
5561-
"BaselineVersion": "4.7.1",
5562+
"BaselineVersion": "4.7.2",
55625563
"InboxOn": {
55635564
"netcoreapp3.0": "4.0.4.0",
5564-
"netcoreapp3.1": "4.0.5.0",
5565+
"netcoreapp3.1": "4.0.5.1",
55655566
"uap10.0.16300": "4.0.5.0"
55665567
},
55675568
"AssemblyVersionInPackageVersion": {
55685569
"4.0.0.0": "4.0.0",
55695570
"4.0.1.0": "4.3.0",
55705571
"4.0.2.0": "4.4.0",
55715572
"4.0.3.0": "4.5.0",
5573+
"4.0.3.1": "4.5.1",
55725574
"4.0.4.0": "4.6.0",
5573-
"4.0.5.0": "4.7.0"
5575+
"4.0.5.0": "4.7.0",
5576+
"4.0.5.1": "4.7.2"
55745577
}
55755578
},
55765579
"System.Text.Json": {
@@ -6644,4 +6647,4 @@
66446647
"System.Xml.XDocument"
66456648
]
66466649
}
6647-
}
6650+
}

src/System.Text.Encodings.Web/Directory.Build.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project>
22
<Import Project="..\Directory.Build.props" />
33
<PropertyGroup>
4-
<AssemblyVersion>4.0.5.0</AssemblyVersion>
5-
<PackageVersion>4.7.1</PackageVersion>
4+
<AssemblyVersion>4.0.5.1</AssemblyVersion>
5+
<PackageVersion>4.7.2</PackageVersion>
66
<StrongNameKeyId>Open</StrongNameKeyId>
77
<IsNETCoreApp>true</IsNETCoreApp>
88
<IsUAP>true</IsUAP>

src/System.Text.Encodings.Web/src/System.Text.Encodings.Web.csproj

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Configurations>netstandard-Debug;netstandard-Release;netstandard2.1-Debug;netstandard2.1-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release;net461-Debug;net461-Release;netfx-Debug;netfx-Release</Configurations>
77
</PropertyGroup>
88
<ItemGroup>
9+
<Compile Include="System\IO\TextWriterExtensions.cs" />
910
<Compile Include="System\Text\Encodings\Web\HexUtil.cs" />
1011
<Compile Include="System\Text\Encodings\Web\HtmlEncoder.cs" />
1112
<Compile Include="System\Text\Encodings\Web\JavaScriptEncoder.cs" />
@@ -27,6 +28,9 @@
2728
<Compile Include="$(CommonPath)\CoreLib\System\Text\UnicodeUtility.cs">
2829
<Link>System\Text\UnicodeUtility.cs</Link>
2930
</Compile>
31+
<Compile Include="$(CommonPath)\CoreLib\System\Text\ValueStringBuilder.cs">
32+
<Link>System\Text\ValueStringBuilder.cs</Link>
33+
</Compile>
3034
</ItemGroup>
3135
<ItemGroup>
3236
<Reference Include="System.Memory" />
@@ -41,4 +45,7 @@
4145
<Reference Include="System.Runtime.Extensions" />
4246
<Reference Include="System.Threading" />
4347
</ItemGroup>
48+
<ItemGroup Condition="'$(TargetGroup)' != 'netstandard2.1'">
49+
<Reference Include="System.Buffers" />
50+
</ItemGroup>
4451
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics;
5+
6+
#if !(netcoreapp || netcoreapp30 || netstandard21)
7+
using System.Buffers;
8+
#endif
9+
10+
namespace System.IO
11+
{
12+
internal static class TextWriterExtensions
13+
{
14+
/// <summary>
15+
/// Writes a partial string (given offset and count) to the underlying TextWriter.
16+
/// </summary>
17+
public static void WritePartialString(this TextWriter writer, string value, int offset, int count)
18+
{
19+
Debug.Assert(writer != null);
20+
Debug.Assert(value != null);
21+
22+
if (offset == 0 && count == value.Length)
23+
{
24+
// on all platforms, prefer TextWriter.Write(string) if no slicing is required
25+
writer.Write(value);
26+
}
27+
else
28+
{
29+
// if slicing is required, call TextWriter.Write(ROS<char>) if available;
30+
// otherwise rent an array and implement the Write routine ourselves
31+
ReadOnlySpan<char> sliced = value.AsSpan(offset, count);
32+
#if netcoreapp || netcoreapp30 || netstandard21
33+
writer.Write(sliced);
34+
#else
35+
char[] rented = ArrayPool<char>.Shared.Rent(sliced.Length);
36+
sliced.CopyTo(rented);
37+
writer.Write(rented, 0, sliced.Length);
38+
ArrayPool<char>.Shared.Return(rented);
39+
#endif
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)