diff --git a/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs b/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs index 0889994b493..7528431810a 100644 --- a/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs +++ b/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcBase.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Buffers.Binary; using System.Collections.Generic; using System.Collections.Concurrent; using System.Globalization; @@ -738,7 +739,7 @@ public async Task RunPacketReadLoopAsync() } NodePacketType packetType = (NodePacketType)_headerByte[0]; - int packetLength = BitConverter.ToInt32(_headerByte, 1); + int packetLength = BinaryPrimitives.ReadInt32LittleEndian(new Span(_headerByte, 1, 4)); _readBufferMemoryStream.SetLength(packetLength); byte[] packetData = _readBufferMemoryStream.GetBuffer(); @@ -1027,7 +1028,7 @@ private void HeaderReadComplete(IAsyncResult result) return; } - int packetLength = BitConverter.ToInt32(_headerByte, 1); + int packetLength = BinaryPrimitives.ReadInt32LittleEndian(new Span(_headerByte, 1, 4)); MSBuildEventSource.Log.PacketReadSize(packetLength); // Ensures the buffer is at least this length. diff --git a/src/Shared/MSBuildNameIgnoreCaseComparer.cs b/src/Shared/MSBuildNameIgnoreCaseComparer.cs index e5f0f0ad199..d0930cc0e19 100644 --- a/src/Shared/MSBuildNameIgnoreCaseComparer.cs +++ b/src/Shared/MSBuildNameIgnoreCaseComparer.cs @@ -149,7 +149,14 @@ public int GetHashCode(string obj, int start, int length) // the string, and not the null terminator etc. if (length == 1) { - val &= 0xFFFF; + if (BitConverter.IsLittleEndian) + { + val &= 0xFFFF; + } + else + { + val &= unchecked((int)0xFFFF0000); + } } hash1 = ((hash1 << 5) + hash1 + (hash1 >> 27)) ^ val; @@ -162,7 +169,14 @@ public int GetHashCode(string obj, int start, int length) val = pint[1] & 0x00DF00DF; if (length == 3) { - val &= 0xFFFF; + if (BitConverter.IsLittleEndian) + { + val &= 0xFFFF; + } + else + { + val &= unchecked((int)0xFFFF0000); + } } hash2 = ((hash2 << 5) + hash2 + (hash2 >> 27)) ^ val;