Files
reverse-engineering-anything/tests/fixtures/peCertificateAllowance.ts
T
RRFZandmorluto 8c83886891 fix(pe): report exhausted certificate decoder allowances as resource limits (#7881)
* fix(pe): report exhausted certificate decoder allowances as resource limits

A PKCS#7 payload that exhausted the fixed 64 KiB decoded-text or 16,384-value ASN.1 allowance was refused as malformed input with advice to correct request fields. Keep the allowance and limit on the decoder failure and report it as a nonretryable resource_constraint with fixed-allowance recovery.

Fixes #7531

* test(pe): cover certificate allowances through MCP

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-10-29 07:36:56 +08:00

44 lines
1.5 KiB
TypeScript

import { pkcs7SignedDataFixture } from "../../src/native/pe/PeCertificates.fixture.js";
import { readAsn1 } from "../../src/native/pe/PeCertificateAsn1.js";
/** One DER TLV with a minimal definite length. */
const derValue = (tag: number, ...parts: Buffer[]): Buffer => {
const content = Buffer.concat(parts);
const octets: number[] = [];
for (let rest = content.length; rest > 0; rest = Math.floor(rest / 256))
octets.unshift(rest % 256);
const length =
content.length < 0x80
? [content.length]
: [0x80 | octets.length, ...octets];
return Buffer.concat([Buffer.from([tag, ...length]), content]);
};
/** The fixture's SignedData with its one certificate repeated `count` times. */
export const repeatedCertificateSignedData = (count: number): Buffer => {
const fixture = pkcs7SignedDataFixture();
const raw = (node: { start: number; end: number } | undefined): Buffer => {
if (node === undefined) throw new Error("Unexpected fixture layout");
return fixture.subarray(node.start, node.end);
};
const [type, explicit] = readAsn1(fixture).children;
const [version, digests, encapsulated, certificates, signers] =
explicit?.children[0]?.children ?? [];
const certificate = raw(certificates?.children[0]);
return derValue(
0x30,
raw(type),
derValue(
0xa0,
derValue(
0x30,
raw(version),
raw(digests),
raw(encapsulated),
derValue(0xa0, ...Array.from({ length: count }, () => certificate)),
raw(signers),
),
),
);
};