test(deno): share Intel trailer fixture records (#15607)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-01 20:35:19 +00:00
1 parent 1fe1aa975c
commit 39ec1f7113
2 files changed
+17 -31

No files matched your search

+13 -8
View File
@@ -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`.
@@ -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;