From aeda49954b805f80dfafa5d5b971d5bfb3e73043 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Thu, 17 Oct 2019 21:05:35 -0400 Subject: Fix invalid ComputeHash from ByteByffer array computation --- Mono.Security.Cryptography/CryptoService.cs | 2 +- Test/Mono.Cecil.Tests/PortablePdbTests.cs | 37 ++++++++++++++++++++++++++++ Test/Resources/assemblies/foo.dll | Bin 0 -> 3072 bytes Test/Resources/assemblies/hello2.exe | Bin 0 -> 3584 bytes 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 Test/Resources/assemblies/foo.dll create mode 100644 Test/Resources/assemblies/hello2.exe diff --git a/Mono.Security.Cryptography/CryptoService.cs b/Mono.Security.Cryptography/CryptoService.cs index 013e001..dd9613f 100644 --- a/Mono.Security.Cryptography/CryptoService.cs +++ b/Mono.Security.Cryptography/CryptoService.cs @@ -146,7 +146,7 @@ namespace Mono.Cecil { using (var crypto_stream = new CryptoStream (Stream.Null, sha1, CryptoStreamMode.Write)) { for (int i = 0; i < buffers.Length; i++) { - crypto_stream.Write (buffers [0].buffer, 0, buffers [0].length); + crypto_stream.Write (buffers [i].buffer, 0, buffers [i].length); } } diff --git a/Test/Mono.Cecil.Tests/PortablePdbTests.cs b/Test/Mono.Cecil.Tests/PortablePdbTests.cs index 6e1efbc..e741865 100644 --- a/Test/Mono.Cecil.Tests/PortablePdbTests.cs +++ b/Test/Mono.Cecil.Tests/PortablePdbTests.cs @@ -683,5 +683,42 @@ class Program using (var module = ModuleDefinition.ReadModule (destination, new ReaderParameters { SymbolReaderProvider = new PortablePdbReaderProvider () })) { } } + + [Test] + public void DoubleWriteAndReadAgainModuleWithDeterministicMvid () + { + Guid mvid1_in, mvid1_out, mvid2_in, mvid2_out; + + { + const string resource = "foo.dll"; + string destination = Path.GetTempFileName (); + + using (var module = GetResourceModule (resource, new ReaderParameters { })) { + mvid1_in = module.Mvid; + module.Write (destination, new WriterParameters { DeterministicMvid = true }); + } + + using (var module = ModuleDefinition.ReadModule (destination, new ReaderParameters { })) { + mvid1_out = module.Mvid; + } + } + + { + const string resource = "hello2.exe"; + string destination = Path.GetTempFileName (); + + using (var module = GetResourceModule (resource, new ReaderParameters { })) { + mvid2_in = module.Mvid; + module.Write (destination, new WriterParameters { DeterministicMvid = true }); + } + + using (var module = ModuleDefinition.ReadModule (destination, new ReaderParameters { })) { + mvid2_out = module.Mvid; + } + } + + Assert.AreNotEqual (mvid1_in, mvid2_in); + Assert.AreNotEqual (mvid1_out, mvid2_out); + } } } diff --git a/Test/Resources/assemblies/foo.dll b/Test/Resources/assemblies/foo.dll new file mode 100644 index 0000000..56b17e0 Binary files /dev/null and b/Test/Resources/assemblies/foo.dll differ diff --git a/Test/Resources/assemblies/hello2.exe b/Test/Resources/assemblies/hello2.exe new file mode 100644 index 0000000..6cc52a9 Binary files /dev/null and b/Test/Resources/assemblies/hello2.exe differ -- cgit v1.2.3