mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
test(pe): share named resource fixtures (#16267)
This commit is contained in:
1 parent
100dcabeb6
commit
ee85bd9b8f
1 file changed
+19
-42
@@ -721,6 +721,13 @@ describe("PE resource ownership boundaries", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const seaResource = (language: number, payload: string) => ({
|
||||
type: 10,
|
||||
name: "NODE_SEA_BLOB",
|
||||
language,
|
||||
payload: Buffer.from(payload),
|
||||
});
|
||||
|
||||
const probeSeaName = (bytes: Buffer) =>
|
||||
hasPeResourceName(
|
||||
bytes.subarray(0, 64),
|
||||
@@ -813,13 +820,8 @@ it.each([
|
||||
|
||||
it("locates every language payload of a named resource with the bounded walk", async () => {
|
||||
const fixture = peResourceFixture(false, [
|
||||
{ type: 10, name: "NODE_SEA_BLOB", language: 1, payload: Buffer.from("a") },
|
||||
{
|
||||
type: 10,
|
||||
name: "NODE_SEA_BLOB",
|
||||
language: 2,
|
||||
payload: Buffer.from("bc"),
|
||||
},
|
||||
seaResource(1, "a"),
|
||||
seaResource(2, "bc"),
|
||||
{ type: 10, name: "OTHER", language: 1, payload: Buffer.from("d") },
|
||||
]);
|
||||
const report = await parse(fixture.bytes);
|
||||
@@ -836,9 +838,7 @@ it("locates every language payload of a named resource with the bounded walk", a
|
||||
});
|
||||
|
||||
it("reports a named resource that cannot resolve to a payload as malformed", async () => {
|
||||
const fixture = peResourceFixture(false, [
|
||||
{ type: 10, name: "NODE_SEA_BLOB", language: 1, payload: Buffer.from("a") },
|
||||
]);
|
||||
const fixture = peResourceFixture(false, [seaResource(1, "a")]);
|
||||
fixture.bytes.writeUInt32LE(0xffff_fff0, fixture.dataOffsets[0]!);
|
||||
await expect(payloadsOf(fixture.bytes)).rejects.toMatchObject({
|
||||
kind: "malformed",
|
||||
@@ -846,9 +846,7 @@ it("reports a named resource that cannot resolve to a payload as malformed", asy
|
||||
});
|
||||
|
||||
it("distinguishes a backed directory beyond the budget from a truncated directory", async () => {
|
||||
const fixture = peResourceFixture(false, [
|
||||
{ type: 10, name: "NODE_SEA_BLOB", language: 1, payload: Buffer.from("a") },
|
||||
]);
|
||||
const fixture = peResourceFixture(false, [seaResource(1, "a")]);
|
||||
await expect(
|
||||
payloadsOf(fixture.bytes, "NODE_SEA_BLOB", 3),
|
||||
).resolves.toHaveLength(1);
|
||||
@@ -872,7 +870,7 @@ it("distinguishes a backed directory beyond the budget from a truncated director
|
||||
|
||||
it("keeps an out-of-interval name unresolved beside a confirmed resource", async () => {
|
||||
const fixture = peResourceFixture(false, [
|
||||
{ type: 10, name: "NODE_SEA_BLOB", language: 1, payload: Buffer.from("a") },
|
||||
seaResource(1, "a"),
|
||||
{ type: 10, name: "OTHER", language: 1, payload: Buffer.from("b") },
|
||||
]);
|
||||
const [root, names] = fixture.directoryOffsets;
|
||||
@@ -908,7 +906,7 @@ it("keeps an out-of-interval name unresolved beside a confirmed resource", async
|
||||
|
||||
it("fails closed when a duplicate resource type branch cannot be read beside the named resource", async () => {
|
||||
const fixture = peResourceFixture(false, [
|
||||
{ type: 10, name: "NODE_SEA_BLOB", language: 1, payload: Buffer.from("a") },
|
||||
seaResource(1, "a"),
|
||||
{ type: 11, name: "OTHER", language: 1, payload: Buffer.from("b") },
|
||||
]);
|
||||
// Root type entries follow the 16-byte root directory header at 0x400.
|
||||
@@ -928,7 +926,7 @@ it("fails closed when a duplicate resource type branch cannot be read beside the
|
||||
|
||||
it("fails closed when a duplicate resource type branch is a data entry beside the named resource", async () => {
|
||||
const fixture = peResourceFixture(false, [
|
||||
{ type: 10, name: "NODE_SEA_BLOB", language: 1, payload: Buffer.from("a") },
|
||||
seaResource(1, "a"),
|
||||
{ type: 11, name: "OTHER", language: 1, payload: Buffer.from("b") },
|
||||
]);
|
||||
// Retype the second root entry as RT_RCDATA and clear its directory bit.
|
||||
@@ -948,8 +946,8 @@ it("fails closed when a duplicate resource type branch is a data entry beside th
|
||||
|
||||
it("rejects a language directory beside a readable language payload", async () => {
|
||||
const fixture = peResourceFixture(false, [
|
||||
{ type: 10, name: "NODE_SEA_BLOB", language: 1, payload: Buffer.from("a") },
|
||||
{ type: 10, name: "NODE_SEA_BLOB", language: 2, payload: Buffer.from("b") },
|
||||
seaResource(1, "a"),
|
||||
seaResource(2, "b"),
|
||||
]);
|
||||
const leaf = fixture.entryOffsets.findLast(
|
||||
(at) => (fixture.bytes.readUInt32LE(at + 4) & 0x80000000) === 0,
|
||||
@@ -969,14 +967,7 @@ it("rejects a language directory beside a readable language payload", async () =
|
||||
});
|
||||
|
||||
it("matches resource names by their exact UTF-16 bytes without losing source identity", async () => {
|
||||
const fixture = peResourceFixture(false, [
|
||||
{
|
||||
type: 10,
|
||||
name: "NODE_SEA_BLOB",
|
||||
language: 1033,
|
||||
payload: Buffer.from("data"),
|
||||
},
|
||||
]);
|
||||
const fixture = peResourceFixture(false, [seaResource(1033, "data")]);
|
||||
expect(await probeSeaName(fixture.bytes)).toBe(true);
|
||||
const entry = fixture.entryOffsets.find(
|
||||
(at) => (fixture.bytes.readUInt32LE(at) & 0x80000000) !== 0,
|
||||
@@ -1001,14 +992,7 @@ it("matches resource names by their exact UTF-16 bytes without losing source ide
|
||||
});
|
||||
|
||||
it("keeps name probing independent of full resource name/ID partition admission", async () => {
|
||||
const fixture = peResourceFixture(false, [
|
||||
{
|
||||
type: 10,
|
||||
name: "NODE_SEA_BLOB",
|
||||
language: 1033,
|
||||
payload: Buffer.from("data"),
|
||||
},
|
||||
]);
|
||||
const fixture = peResourceFixture(false, [seaResource(1033, "data")]);
|
||||
const names = fixture.directoryOffsets[1];
|
||||
if (names === undefined) throw new Error("Expected resource names directory");
|
||||
fixture.bytes.writeUInt16LE(0, names + 12);
|
||||
@@ -1021,14 +1005,7 @@ it("keeps name probing independent of full resource name/ID partition admission"
|
||||
});
|
||||
|
||||
it("keeps raw name probing separate from full resource-name alignment admission", async () => {
|
||||
const fixture = peResourceFixture(false, [
|
||||
{
|
||||
type: 10,
|
||||
name: "NODE_SEA_BLOB",
|
||||
language: 1033,
|
||||
payload: Buffer.from("data"),
|
||||
},
|
||||
]);
|
||||
const fixture = peResourceFixture(false, [seaResource(1033, "data")]);
|
||||
const entry = fixture.entryOffsets.find(
|
||||
(at) => (fixture.bytes.readUInt32LE(at) & 0x80000000) !== 0,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user