fix(managed): classify truncated signatures as malformed (#598)
* fix(managed): classify truncated signatures as malformed Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> * fix(managed): use typed signature parsing failures Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> * chore(managed): refresh signature schema commitments Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> --------- Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
@@ -545,9 +545,9 @@
|
||||
"mcp_prompts": 6
|
||||
},
|
||||
"digests": {
|
||||
"tools_sha256": "6b821e70d26368f3e19d405f8ac712855da19d59c90dd2d462d49ff1f9d73eb0",
|
||||
"tools_sha256": "7849b6f39bed200cfbf5f4d09ba3f9e0661824efb5753ae2edde8ef2fb66535e",
|
||||
"prompts_sha256": "4762db348821fec787a5b8c6423f2c48a71f6f0ec2afee97b16ad69030ec504b",
|
||||
"combined_sha256": "bc45ad5ad2c7e1d9b5b11d17c3ea051a33ed04b6ce2ed0cdfd40a95502239d02",
|
||||
"combined_sha256": "5bb3f994a3c4d0c87a34ff5aab4e28141b5fa6f3a98b5ae7e95686d85d9d983e",
|
||||
"providers_sha256": "2ae8b85b20be338739e500549d275e78e875aaa10235d2ca283f0ade7787da90"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"manifest_id": "ecm_d3116f62b6cd65e63c9fed5c4bc9edd604be7c67fdef1b8f7375fd2c84b85682",
|
||||
"manifest_id": "ecm_7da021af56cf2eb25489ed7ce494bfe92244e791fa3b5ad5a238a5eb14a23d9a",
|
||||
"verifier": {
|
||||
"id": "rea-managed-conformance",
|
||||
"version": "1"
|
||||
@@ -13,7 +13,7 @@
|
||||
"skill_digests": [
|
||||
{
|
||||
"skill_id": "reverse-engineer-anything",
|
||||
"sha256": "11e1170733312681ce2f2d771f1a9ece6c1f0505ef919d122790583857f3094c"
|
||||
"sha256": "411d5b61e237e3b9b2cb9b3a987d83a36134a2ea1810ddd8d9f695dc05709f5b"
|
||||
}
|
||||
],
|
||||
"claims": [
|
||||
|
||||
@@ -4,7 +4,7 @@ description: Reverse engineer native, managed, Electron/JavaScript, packaged, an
|
||||
metadata:
|
||||
version: "24"
|
||||
tool_count: 116
|
||||
catalog_digest: "bc45ad5ad2c7e1d9b5b11d17c3ea051a33ed04b6ce2ed0cdfd40a95502239d02"
|
||||
catalog_digest: "5bb3f994a3c4d0c87a34ff5aab4e28141b5fa6f3a98b5ae7e95686d85d9d983e"
|
||||
---
|
||||
|
||||
# REA
|
||||
|
||||
@@ -292,6 +292,7 @@ const managedParseIssueSchema = z.object({
|
||||
"invalid-heap-index",
|
||||
"invalid-string",
|
||||
"invalid-blob",
|
||||
"unsupported-signature",
|
||||
"invalid-guid",
|
||||
"invalid-resource",
|
||||
]),
|
||||
|
||||
@@ -110,3 +110,39 @@ describe("managed member inspection", () => {
|
||||
expect(result.coverage).toMatchObject({ state: "complete", issues: [] });
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
Buffer.alloc(0),
|
||||
Buffer.from([0]),
|
||||
Buffer.from([0, 0, 0x12]),
|
||||
Buffer.from([0x10, 0x80]),
|
||||
Buffer.from([0, 0xe0]),
|
||||
])(
|
||||
"marks incomplete or reserved method signatures malformed: %j",
|
||||
(methodSignature) => {
|
||||
const bytes = buildManagedPeFixture({ methodSignature });
|
||||
const result = inspectManagedMembersBytes(
|
||||
bytes,
|
||||
managedPeFixtureTarget(bytes),
|
||||
);
|
||||
expect(result.methods[0]?.signature).toMatchObject({
|
||||
parse_status: "malformed",
|
||||
kind: "unknown",
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps an admitted but unimplemented element type unsupported", () => {
|
||||
// ECMA-335 ELEMENT_TYPE_ARRAY is valid, but multidimensional arrays are not decoded here.
|
||||
const bytes = buildManagedPeFixture({
|
||||
fieldSignature: Buffer.from([6, 0x14, 8, 1, 0, 0]),
|
||||
});
|
||||
const result = inspectManagedMembersBytes(
|
||||
bytes,
|
||||
managedPeFixtureTarget(bytes),
|
||||
);
|
||||
expect(result.fields[0]?.signature).toMatchObject({
|
||||
parse_status: "unsupported",
|
||||
issue: "unsupported element type 0x14",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
managedFailure,
|
||||
ManagedReaderFailure,
|
||||
} from "./ManagedReaderFailure.js";
|
||||
import type { ManagedMemberInspection } from "../domain/managedArtifact.js";
|
||||
import {
|
||||
type ManagedMetadataLayout,
|
||||
@@ -208,7 +212,13 @@ const readCompressed = (
|
||||
offset: number,
|
||||
): { readonly value: number; readonly next: number } => {
|
||||
const first = bytes[offset];
|
||||
if (first === undefined) throw new RangeError("truncated compressed integer");
|
||||
if (first === undefined)
|
||||
throw managedFailure(
|
||||
"invalid-blob",
|
||||
"signature",
|
||||
"truncated compressed integer",
|
||||
offset,
|
||||
);
|
||||
if ((first & 0x80) === 0) return { value: first, next: offset + 1 };
|
||||
const second = bytes[offset + 1];
|
||||
if ((first & 0xc0) === 0x80 && second !== undefined)
|
||||
@@ -227,7 +237,12 @@ const readCompressed = (
|
||||
(first & 0x1f) * 0x01_00_00_00 + b1 * 0x01_00_00 + b2 * 0x0100 + b3,
|
||||
next: offset + 4,
|
||||
};
|
||||
throw new RangeError("reserved compressed integer");
|
||||
throw managedFailure(
|
||||
"invalid-blob",
|
||||
"signature",
|
||||
"reserved compressed integer",
|
||||
offset,
|
||||
);
|
||||
};
|
||||
|
||||
const ELEMENT_TYPES = new Map<number, string>([
|
||||
@@ -260,7 +275,13 @@ const readTypeSignature = (
|
||||
offset: number,
|
||||
): { readonly value: string; readonly next: number } => {
|
||||
const kind = blob[offset];
|
||||
if (kind === undefined) throw new RangeError("truncated type signature");
|
||||
if (kind === undefined)
|
||||
throw managedFailure(
|
||||
"invalid-blob",
|
||||
"signature",
|
||||
"truncated type signature",
|
||||
offset,
|
||||
);
|
||||
const named = ELEMENT_TYPES.get(kind);
|
||||
if (named !== undefined) return { value: named, next: offset + 1 };
|
||||
const suffix = ELEMENT_TYPE_SUFFIXES.get(kind);
|
||||
@@ -287,7 +308,12 @@ const readTypeSignature = (
|
||||
const variable = readCompressed(blob, offset + 1);
|
||||
return { value: `var:${String(variable.value)}`, next: variable.next };
|
||||
}
|
||||
throw new RangeError(`unsupported element type 0x${kind.toString(16)}`);
|
||||
throw managedFailure(
|
||||
"unsupported-signature",
|
||||
"signature",
|
||||
`unsupported element type 0x${kind.toString(16)}`,
|
||||
offset,
|
||||
);
|
||||
};
|
||||
|
||||
const callingConvention = (value: number): string => {
|
||||
@@ -314,7 +340,8 @@ export const signature = (blob: Buffer): ManagedSignature => {
|
||||
raw_sha256: sha256Bytes(blob),
|
||||
};
|
||||
try {
|
||||
if (blob.length === 0) throw new RangeError("empty signature");
|
||||
if (blob.length === 0)
|
||||
throw managedFailure("invalid-blob", "signature", "empty signature", 0);
|
||||
const first = blob[0] ?? 0;
|
||||
if ((first & 0x0f) === 6) {
|
||||
const fieldType = readTypeSignature(blob, 1);
|
||||
@@ -362,17 +389,26 @@ export const signature = (blob: Buffer): ManagedSignature => {
|
||||
issue: offset === blob.length ? null : "Trailing signature data",
|
||||
};
|
||||
} catch (cause: unknown) {
|
||||
if (!(cause instanceof ManagedReaderFailure)) throw cause;
|
||||
if (
|
||||
cause.issue.code !== "invalid-blob" &&
|
||||
cause.issue.code !== "unsupported-signature"
|
||||
)
|
||||
throw cause;
|
||||
return {
|
||||
...raw,
|
||||
kind: "unknown",
|
||||
parse_status: cause instanceof RangeError ? "unsupported" : "malformed",
|
||||
parse_status:
|
||||
cause.issue.code === "unsupported-signature"
|
||||
? "unsupported"
|
||||
: "malformed",
|
||||
calling_convention: null,
|
||||
generic_parameter_count: null,
|
||||
parameter_count: null,
|
||||
return_type: null,
|
||||
parameter_types: [],
|
||||
field_type: null,
|
||||
issue: cause instanceof Error ? cause.message : "Signature parse failed",
|
||||
issue: cause.issue.detail,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user