Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/IO/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,9 @@ public static byte[] ReadAllBytes(string path)

int index = 0;
int count = (int)fileLength;
byte[] bytes = new byte[count];
// The entire array is overwritten by the read loop below (an exception is thrown
// if the file is truncated before all the bytes are read), so it does not need to be zeroed.
byte[] bytes = GC.AllocateUninitializedArray<byte>(count);
Comment thread
adamsitnik marked this conversation as resolved.
while (count > 0)
{
int n = RandomAccess.ReadAtOffset(sfh, bytes.AsSpan(index, count), index);
Expand Down Expand Up @@ -1225,7 +1227,9 @@ private static async Task<byte[]> InternalReadAllBytesAsync(SafeFileHandle sfh,
using (sfh)
{
int index = 0;
byte[] bytes = new byte[count];
// The entire array is overwritten by the read loop below (an exception is thrown
// if the file is truncated before all the bytes are read), so it does not need to be zeroed.
byte[] bytes = GC.AllocateUninitializedArray<byte>(count);
do
{
int n = await RandomAccess.ReadAtOffsetAsync(sfh, bytes.AsMemory(index), index, cancellationToken).ConfigureAwait(false);
Expand Down
Loading