From c74990d987756700a0f754a8fdbc831b6c4877e6 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Tue, 25 Aug 2026 13:52:27 +0200 Subject: [PATCH] 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 --- .../SingleFileBundleTests.cs | 8 +------- .../Properties/AssemblyInfo.cs | 1 + ICSharpCode.Decompiler/SingleFileBundle.cs | 18 +++++++++++------- ILSpy.Tests/LoadedPackageBundleTests.cs | 9 ++------- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/SingleFileBundleTests.cs b/ICSharpCode.Decompiler.Tests/SingleFileBundleTests.cs index 2bc48ee8f..c74451b52 100644 --- a/ICSharpCode.Decompiler.Tests/SingleFileBundleTests.cs +++ b/ICSharpCode.Decompiler.Tests/SingleFileBundleTests.cs @@ -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() diff --git a/ICSharpCode.Decompiler/Properties/AssemblyInfo.cs b/ICSharpCode.Decompiler/Properties/AssemblyInfo.cs index 6a8f0e31c..753d60580 100644 --- a/ICSharpCode.Decompiler/Properties/AssemblyInfo.cs +++ b/ICSharpCode.Decompiler/Properties/AssemblyInfo.cs @@ -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")] diff --git a/ICSharpCode.Decompiler/SingleFileBundle.cs b/ICSharpCode.Decompiler/SingleFileBundle.cs index 2e82f78df..0d3817740 100644 --- a/ICSharpCode.Decompiler/SingleFileBundle.cs +++ b/ICSharpCode.Decompiler/SingleFileBundle.cs @@ -35,15 +35,19 @@ namespace ICSharpCode.Decompiler } } + /// + /// The 32-byte bundle signature: SHA-256 of ".net core bundle". + /// + internal static ReadOnlySpan 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 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 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 diff --git a/ILSpy.Tests/LoadedPackageBundleTests.cs b/ILSpy.Tests/LoadedPackageBundleTests.cs index 3301f1037..07abc769a 100644 --- a/ILSpy.Tests/LoadedPackageBundleTests.cs +++ b/ILSpy.Tests/LoadedPackageBundleTests.cs @@ -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; [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 tempFiles = new();