Skip to content

Commit

Permalink
Merge pull request #7701 from basvdlinden/safe_bytestring_copyfrom_span
Browse files Browse the repository at this point in the history
annotate ByteString.CopyFrom(ReadOnlySpan<byte>) as SecuritySafeCritical
  • Loading branch information
jtattermusch committed Oct 27, 2020
2 parents 022078d + 4c1bb4d commit 9d9c670
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions csharp/src/Google.Protobuf.Test/ByteStringTest.cs
Expand Up @@ -110,6 +110,18 @@ public void CopyFromByteArrayCopiesContents()
Assert.AreEqual(10, bs[0]);
}

[Test]
public void CopyFromReadOnlySpanCopiesContents()
{
byte[] data = new byte[1];
data[0] = 10;
ReadOnlySpan<byte> byteSpan = data;
var bs = ByteString.CopyFrom(byteSpan);
Assert.AreEqual(10, bs[0]);
data[0] = 5;
Assert.AreEqual(10, bs[0]);
}

[Test]
public void ToByteArrayCopiesContents()
{
Expand Down
1 change: 1 addition & 0 deletions csharp/src/Google.Protobuf/ByteString.cs
Expand Up @@ -245,6 +245,7 @@ public static ByteString CopyFrom(byte[] bytes, int offset, int count)
/// are copied, so further modifications to the span will not
/// be reflected in the returned <see cref="ByteString" />.
/// </summary>
[SecuritySafeCritical]
public static ByteString CopyFrom(ReadOnlySpan<byte> bytes)
{
return new ByteString(bytes.ToArray());
Expand Down

0 comments on commit 9d9c670

Please sign in to comment.