From 9bf5df72a69ea1adcf5e43a99708f5302bae4557 Mon Sep 17 00:00:00 2001 From: haykpetros Date: Wed, 5 Aug 2015 05:27:30 -0700 Subject: [PATCH] Added additional check to make sure that data is properly copied to array regardless fo computer/CPU platform (little-endian or big-endian). In case of big-endian platform intermediate array will be reversed prior to copying to destination array. --- SharpCompress/Utility.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SharpCompress/Utility.cs b/SharpCompress/Utility.cs index a6c05f73..6a7c4d72 100644 --- a/SharpCompress/Utility.cs +++ b/SharpCompress/Utility.cs @@ -202,6 +202,10 @@ namespace SharpCompress public static void WriteLittleEndian(byte[] array, int pos, short value) { byte[] newBytes = BitConverter.GetBytes(value); + + if (!BitConverter.IsLittleEndian) + Array.Reverse(newBytes); + Array.Copy(newBytes, 0, array, pos, newBytes.Length); } @@ -234,6 +238,10 @@ namespace SharpCompress public static void WriteLittleEndian(byte[] array, int pos, int value) { byte[] newBytes = BitConverter.GetBytes(value); + + if (!BitConverter.IsLittleEndian) + Array.Reverse(newBytes); + Array.Copy(newBytes, 0, array, pos, newBytes.Length); }