From 39ec1f7113604e1b0fe22dc72b98f93bc6f40ab2 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Wed, 2 Dec 2026 04:35:19 +0800 Subject: [PATCH] test(deno): share Intel trailer fixture records (#15607) --- src/artifacts/deno/DenoStandalone.fixture.ts | 21 +++++++++------ .../deno/DenoStandaloneArtifactReader.test.ts | 27 +++---------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/artifacts/deno/DenoStandalone.fixture.ts b/src/artifacts/deno/DenoStandalone.fixture.ts index 93eb6088eab..d8b0f7778e9 100644 --- a/src/artifacts/deno/DenoStandalone.fixture.ts +++ b/src/artifacts/deno/DenoStandalone.fixture.ts @@ -169,22 +169,27 @@ export const denoMachO = ( }); }; -/** x86_64 Mach-O with no `__SUI` section and a libsui Intel trailer. */ -export const denoIntelTrailer = ( - section: Buffer = buildDenoSection(), -): Buffer => { - const image = thinMachOWithoutDenoSection(); +/** Wire parts of one libsui Intel trailer record. */ +const intelTrailerParts = (section: Buffer): Buffer[] => { const length = Buffer.alloc(8); length.writeBigUInt64LE(BigInt(section.length)); - return Buffer.concat([ - image, + return [ Buffer.from("<~sui-data~>", "latin1"), Buffer.from([0xef, 0xbe, 0xad, 0xde]), length, section, - ]); + ]; }; +export const intelTrailerRecord = (section: Buffer): Buffer => + Buffer.concat(intelTrailerParts(section)); + +/** x86_64 Mach-O with no `__SUI` section and a libsui Intel trailer. */ +export const denoIntelTrailer = ( + section: Buffer = buildDenoSection(), +): Buffer => + Buffer.concat([thinMachOWithoutDenoSection(), ...intelTrailerParts(section)]); + /** * x86_64 Mach-O with one segment, named `segment`, whose file range is * exactly `contents`. diff --git a/src/artifacts/deno/DenoStandaloneArtifactReader.test.ts b/src/artifacts/deno/DenoStandaloneArtifactReader.test.ts index 03ef5e666ff..c9fc91318e8 100644 --- a/src/artifacts/deno/DenoStandaloneArtifactReader.test.ts +++ b/src/artifacts/deno/DenoStandaloneArtifactReader.test.ts @@ -36,6 +36,7 @@ import { denoMachO, denoPe, denoUniversal, + intelTrailerRecord, machOWithSegment, } from "./DenoStandalone.fixture.js"; @@ -693,15 +694,10 @@ it("bounds aggregate hashing of overlapping duplicate sections by carrier size", it("leaves an x64 Mach-O with a libsui sentinel and no d3n0l4nd marker absent", async () => { const image = denoMachO([], { architecture: "x64" }); - const claimed = Buffer.alloc(8); - claimed.writeBigUInt64LE(8n); const bytes = Buffer.concat([ image, Buffer.from("runtime-padding-before-sentinel"), - Buffer.from("<~sui-data~>", "latin1"), - Buffer.from([0xef, 0xbe, 0xad, 0xde]), - claimed, - Buffer.from("notd3n0!"), + intelTrailerRecord(Buffer.from("notd3n0!")), Buffer.from("tail"), ]); const probe = await locateDenoStandalone(bytesHandle(bytes), bytes.length); @@ -982,11 +978,7 @@ it("classifies repeated ELF note headers within the note ceiling's read budget", }); const rejectedIntelSentinels = (count: number): Buffer => { - const sentinel = Buffer.concat([ - Buffer.from("<~sui-data~>", "latin1"), - Buffer.from([0xef, 0xbe, 0xad, 0xde]), - Buffer.alloc(8), - ]); + const sentinel = intelTrailerRecord(Buffer.alloc(0)); return Buffer.concat(Array.from({ length: count }, () => sentinel)); }; @@ -1118,7 +1110,7 @@ it("keeps a native Intel host whose __DATA segment stores an Intel Deno executab it("ignores embedded Intel sentinels in out-of-order overlapping segments and accepts a trailer at their end", async () => { const section = buildDenoSection(); - const trailer = denoIntelTrailer(section).subarray(-section.length - 24); + const trailer = intelTrailerRecord(section); const segmentSize = 72; const header = Buffer.alloc(32 + 3 * segmentSize); header.writeUInt32LE(0xfeedfacf, 0); @@ -1240,17 +1232,6 @@ it("fails closed when the enclosing Intel trailer is truncated around a nested a }); }); -const intelTrailerRecord = (section: Buffer): Buffer => { - const length = Buffer.alloc(8); - length.writeBigUInt64LE(BigInt(section.length)); - return Buffer.concat([ - Buffer.from("<~sui-data~>", "latin1"), - Buffer.from([0xef, 0xbe, 0xad, 0xde]), - length, - section, - ]); -}; - // The search starts at EOF and walks in 1 MiB chunks. const intelTrailerChunkEdge = 2 * 1024 * 1024; const intelTrailerChunkSize = 1024 * 1024;