From 8ad1d7d665c9867621193d4f8362cdb983602cae Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Fri, 19 Mar 2021 11:46:08 +0100 Subject: [PATCH] Big-endian fix: PEBuilder.CalculateChecksum (#49816) * Always use little-endian encoding to compute checksum --- .../src/System/Reflection/PortableExecutable/PEBuilder.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEBuilder.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEBuilder.cs index 112359f..a2de3a1 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEBuilder.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEBuilder.cs @@ -549,7 +549,8 @@ namespace System.Reflection.PortableExecutable while (ptr < end) { - checksum = AggregateChecksum(checksum, *(ushort*)ptr); + // little-endian encoding: + checksum = AggregateChecksum(checksum, (ushort)(ptr[1] << 8 | ptr[0])); ptr += sizeof(ushort); } } -- 2.7.4