Browse Source

Share the bundle signature with the tests instead of copying it

Two test fixtures carried their own copy of the 32-byte signature, which
would silently drift from the real one. The signature is now an internal
member of SingleFileBundle and ILSpy.Tests gets internals access to the
decompiler assembly, matching what ILSpyX already grants it.

Assisted-by: Claude:claude-fable-5:Claude Code
pull/4048/head
Christoph Wille 3 weeks ago
parent
commit
c74990d987
  1. 8
      ICSharpCode.Decompiler.Tests/SingleFileBundleTests.cs
  2. 1
      ICSharpCode.Decompiler/Properties/AssemblyInfo.cs
  3. 18
      ICSharpCode.Decompiler/SingleFileBundle.cs
  4. 9
      ILSpy.Tests/LoadedPackageBundleTests.cs

8
ICSharpCode.Decompiler.Tests/SingleFileBundleTests.cs

@ -26,13 +26,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -26,13 +26,7 @@ namespace ICSharpCode.Decompiler.Tests
[TestFixture]
public class SingleFileBundleTests
{
// The 32-byte bundle signature (SHA-256 of ".net core bundle"), as in SingleFileBundle.IsBundle.
static readonly byte[] Signature = new byte[] {
0x8b, 0x12, 0x02, 0xb9, 0x6a, 0x61, 0x20, 0x38,
0x72, 0x7b, 0x93, 0x02, 0x14, 0xd7, 0xa0, 0x32,
0x13, 0xf5, 0xb9, 0xe6, 0xef, 0xae, 0x33, 0x18,
0xee, 0x3b, 0x2d, 0xce, 0x24, 0xb3, 0x6a, 0xae
};
static readonly byte[] Signature = SingleFileBundle.BundleSignature.ToArray();
[Test]
public unsafe void IsBundle_SignatureAtStart_DoesNotReadBeforeBuffer()

1
ICSharpCode.Decompiler/Properties/AssemblyInfo.cs

@ -36,6 +36,7 @@ using System.Runtime.InteropServices; @@ -36,6 +36,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyInformationalVersion(DecompilerVersionInfo.FullVersionWithCommitHash)]
[assembly: InternalsVisibleTo("ICSharpCode.Decompiler.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004dcf3979c4e902efa4dd2163a039701ed5822e6f1134d77737296abbb97bf0803083cfb2117b4f5446a217782f5c7c634f9fe1fc60b4c11d62c5b3d33545036706296d31903ddcf750875db38a8ac379512f51620bb948c94d0831125fbc5fe63707cbb93f48c1459c4d1749eb7ac5e681a2f0d6d7c60fa527a3c0b8f92b02bf")]
[assembly: InternalsVisibleTo("ILSpy.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004dcf3979c4e902efa4dd2163a039701ed5822e6f1134d77737296abbb97bf0803083cfb2117b4f5446a217782f5c7c634f9fe1fc60b4c11d62c5b3d33545036706296d31903ddcf750875db38a8ac379512f51620bb948c94d0831125fbc5fe63707cbb93f48c1459c4d1749eb7ac5e681a2f0d6d7c60fa527a3c0b8f92b02bf")]
[assembly: SuppressMessage("Microsoft.Usage", "CA2243:AttributeStringLiteralsShouldParseCorrectly",
Justification = "AssemblyInformationalVersion does not need to be a parsable version")]

18
ICSharpCode.Decompiler/SingleFileBundle.cs

@ -35,15 +35,19 @@ namespace ICSharpCode.Decompiler @@ -35,15 +35,19 @@ namespace ICSharpCode.Decompiler
}
}
/// <summary>
/// The 32-byte bundle signature: SHA-256 of ".net core bundle".
/// </summary>
internal static ReadOnlySpan<byte> BundleSignature => new byte[] {
0x8b, 0x12, 0x02, 0xb9, 0x6a, 0x61, 0x20, 0x38,
0x72, 0x7b, 0x93, 0x02, 0x14, 0xd7, 0xa0, 0x32,
0x13, 0xf5, 0xb9, 0xe6, 0xef, 0xae, 0x33, 0x18,
0xee, 0x3b, 0x2d, 0xce, 0x24, 0xb3, 0x6a, 0xae
};
public static unsafe bool IsBundle(byte* data, long size, out long bundleHeaderOffset)
{
ReadOnlySpan<byte> bundleSignature = new byte[] {
// 32 bytes represent the bundle signature: SHA-256 for ".net core bundle"
0x8b, 0x12, 0x02, 0xb9, 0x6a, 0x61, 0x20, 0x38,
0x72, 0x7b, 0x93, 0x02, 0x14, 0xd7, 0xa0, 0x32,
0x13, 0xf5, 0xb9, 0xe6, 0xef, 0xae, 0x33, 0x18,
0xee, 0x3b, 0x2d, 0xce, 0x24, 0xb3, 0x6a, 0xae
};
ReadOnlySpan<byte> bundleSignature = BundleSignature;
// 'end' is the last position at which a full signature still fits, so it is a valid
// candidate itself: a memory-mapped view reports the exact file length on Unix (Windows

9
ILSpy.Tests/LoadedPackageBundleTests.cs

@ -23,6 +23,7 @@ using System.IO.Compression; @@ -23,6 +23,7 @@ using System.IO.Compression;
using System.Linq;
using System.Text;
using ICSharpCode.Decompiler;
using ICSharpCode.ILSpyX;
using NUnit.Framework;
@ -38,13 +39,7 @@ namespace ICSharpCode.ILSpy.Tests; @@ -38,13 +39,7 @@ namespace ICSharpCode.ILSpy.Tests;
[TestFixture]
public class LoadedPackageBundleTests
{
// The 32-byte bundle signature (SHA-256 of ".net core bundle"), as in SingleFileBundle.IsBundle.
static readonly byte[] Signature = new byte[] {
0x8b, 0x12, 0x02, 0xb9, 0x6a, 0x61, 0x20, 0x38,
0x72, 0x7b, 0x93, 0x02, 0x14, 0xd7, 0xa0, 0x32,
0x13, 0xf5, 0xb9, 0xe6, 0xef, 0xae, 0x33, 0x18,
0xee, 0x3b, 0x2d, 0xce, 0x24, 0xb3, 0x6a, 0xae
};
static readonly byte[] Signature = SingleFileBundle.BundleSignature.ToArray();
readonly List<string> tempFiles = new();

Loading…
Cancel
Save