Skip to content

Commit

Permalink
Merge pull request #622 from jeromelaban/dev/jela/mvid-fix
Browse files Browse the repository at this point in the history
Fix invalid ComputeHash from ByteByffer array computation
  • Loading branch information
jbevain authored Oct 18, 2019
2 parents 06da319 + aeda499 commit 99a6d0e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Mono.Security.Cryptography/CryptoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static byte [] ComputeHash (params ByteBuffer [] buffers)

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);
}
}

Expand Down
37 changes: 37 additions & 0 deletions Test/Mono.Cecil.Tests/PortablePdbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -683,5 +683,42 @@ public void WriteAndReadAgainModuleWithDeterministicMvid ()
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);
}
}
}
Binary file added Test/Resources/assemblies/foo.dll
Binary file not shown.
Binary file added Test/Resources/assemblies/hello2.exe
Binary file not shown.

0 comments on commit 99a6d0e

Please sign in to comment.