-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tighten bounds checks around TextEncoder logic
- Replaces unsafe code with safe code where possible - Fixes some surrogate pairs being misinterpreted - Fixes #45994 - Ref: MSRC 62749 (CVE-2021-26701)
- Loading branch information
1 parent
10fccb8
commit f27d337
Showing
24 changed files
with
710 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/libraries/System.Text.Encodings.Web/Directory.Build.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
<Project> | ||
<Import Project="..\Directory.Build.props" /> | ||
<PropertyGroup> | ||
<AssemblyVersion>5.0.0.1</AssemblyVersion> | ||
<PackageVersion>5.0.1</PackageVersion> | ||
<HarvestVersion>4.5.1</HarvestVersion> | ||
<StrongNameKeyId>Open</StrongNameKeyId> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/libraries/System.Text.Encodings.Web/src/System/IO/TextWriterExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
|
||
#if !(NETCOREAPP || NETSTANDARD2_1) | ||
using System.Buffers; | ||
#endif | ||
|
||
namespace System.IO | ||
{ | ||
internal static class TextWriterExtensions | ||
{ | ||
/// <summary> | ||
/// Writes a partial string (given offset and count) to the underlying TextWriter. | ||
/// </summary> | ||
public static void WritePartialString(this TextWriter writer, string value, int offset, int count) | ||
{ | ||
Debug.Assert(writer != null); | ||
Debug.Assert(value != null); | ||
|
||
if (offset == 0 && count == value.Length) | ||
{ | ||
// on all platforms, prefer TextWriter.Write(string) if no slicing is required | ||
writer.Write(value); | ||
} | ||
else | ||
{ | ||
// if slicing is required, call TextWriter.Write(ROS<char>) if available; | ||
// otherwise rent an array and implement the Write routine ourselves | ||
ReadOnlySpan<char> sliced = value.AsSpan(offset, count); | ||
#if NETCOREAPP || NETSTANDARD2_1 | ||
writer.Write(sliced); | ||
#else | ||
char[] rented = ArrayPool<char>.Shared.Rent(sliced.Length); | ||
sliced.CopyTo(rented); | ||
writer.Write(rented, 0, sliced.Length); | ||
ArrayPool<char>.Shared.Return(rented); | ||
#endif | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.