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
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,9 @@ public bool TryGetDotnetPathByArchitecture(
using var headerReader = _fileHelper.GetStream(path, FileMode.Open, FileAccess.Read);
var magicBytes = new byte[4];
var cpuInfoBytes = new byte[4];
#pragma warning disable CA2022 // Avoid inexact read with 'Stream.Read'
headerReader.Read(magicBytes, 0, magicBytes.Length);
headerReader.Read(cpuInfoBytes, 0, cpuInfoBytes.Length);
#pragma warning restore CA2022 // Avoid inexact read with 'Stream.Read'

ReadExactly(headerReader, magicBytes, 0, magicBytes.Length);
ReadExactly(headerReader, cpuInfoBytes, 0, cpuInfoBytes.Length);

var magic = BitConverter.ToUInt32(magicBytes, 0);
var cpuInfo = BitConverter.ToUInt32(cpuInfoBytes, 0);
Expand All @@ -435,6 +434,27 @@ public bool TryGetDotnetPathByArchitecture(
return null;
}

#if NET
private static void ReadExactly(Stream stream, byte[] buffer, int offset, int count)
{
stream.ReadExactly(buffer, offset, count);
}
#else
private static void ReadExactly(Stream stream, byte[] buffer, int offset, int count)
{
while (count > 0)
{
int read = stream.Read(buffer, offset, count);
if (read <= 0)
{
throw new EndOfStreamException();
}
offset += read;
count -= read;
}
}
#endif

internal enum MacOsCpuType : uint
{
Arm64Magic = 0x0100000c,
Expand Down