Skip to content
Merged
Changes from 3 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,14 @@ 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'

#if NET
headerReader.ReadExactly(magicBytes, 0, magicBytes.Length);
headerReader.ReadExactly(cpuInfoBytes, 0, cpuInfoBytes.Length);
#else
ReadExist(headerReader, magicBytes, 0, magicBytes.Length);
ReadExist(headerReader, cpuInfoBytes, 0, cpuInfoBytes.Length);
#endif

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

private static void ReadExist(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;
}
}

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