mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 14:35:45 +00:00
* refactor(domain): give strict UTF-8 decoding one owner with an explicit BOM policy * fix(domain): keep the leading-BOM behaviour every migrated UTF-8 decoder had * refactor(domain): read the domain layer's strict UTF-8 through the BOM-policy owner (#10803) Twelve domain decoders built their own fatal TextDecoder with ignoreBOM: true. They now use strictUtf8Decoder("preserve"), which keeps that behaviour: each reads bytes where a leading U+FEFF is content (binary-format names and fields, JSON and XML read byte-for-byte, recorded bodies, registry seeds whose kept bytes are re-emitted). The counted baseline drops from 74 to 62. * refactor(artifacts): read artifact readers' strict UTF-8 through the BOM-policy owner (#10871) Fourteen artifact reader modules (17 sites) built their own fatal TextDecoder. They now take it from strictUtf8Decoder with the policy each had: every one kept a leading BOM (ignoreBOM: true), so they use "preserve"; JavaScriptArtifactFiles keeps it for JavaScript and HTML entries and strips it otherwise, as before. The strict-utf8-decoder baseline drops those 17 sites. * refactor(domain): drop TextDecoder imports left by the strict UTF-8 migration * refactor(application): read MCP registration metadata through the strict UTF-8 owner * refactor(formats): read binary-format readers' strict UTF-8 through the BOM-policy owner (#10903) * refactor(formats): read binary-format readers' strict UTF-8 through the BOM-policy owner * refactor(formats): drop the model readers' unused TextDecoder imports * refactor(browser): read browser capture and fetch strict UTF-8 through the BOM-policy owner (#10935) * refactor(browser): read browser capture and fetch strict UTF-8 through the BOM-policy owner * refactor(native): read LLDB and Mach-O name strict UTF-8 through the BOM-policy owner (#10936) * refactor(native): read LLDB and Mach-O name strict UTF-8 through the BOM-policy owner * refactor(process): read MCP and NDJSON transport frames' strict UTF-8 through the BOM-policy owner (#10937) * refactor(process): read MCP and NDJSON transport frames' strict UTF-8 through the BOM-policy owner * refactor(application): read JSON and file inputs' strict UTF-8 through the BOM-policy owner (#10938) * refactor(application): read JSON and file inputs' strict UTF-8 through the BOM-policy owner * refactor(providers): read IDA, Electron, Ghidra and reference strict UTF-8 through the BOM-policy owner (#10939) * refactor(providers): read IDA, Electron, Ghidra and reference strict UTF-8 through the BOM-policy owner * refactor(evm): read the hex bytecode carrier's strict UTF-8 through the owner and refuse new local decoders (#10940) * refactor(evm): read the hex bytecode carrier's strict UTF-8 through the BOM-policy owner * chore(architecture): match local strict UTF-8 decoders in any option order
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { execFile } from "node:child_process";
|
|
import { promisify } from "node:util";
|
|
import { expect, it } from "vitest";
|
|
import {
|
|
decodeEvmBytecodeCarrier,
|
|
EvmCarrierFailure,
|
|
} from "./EvmBytecodeCarrier.js";
|
|
|
|
it.each(["6000FF", "0x6000ff", " \t0X6000FF\r\n"])(
|
|
"decodes explicit hex without changing selected bytes: %j",
|
|
(text) => {
|
|
expect(
|
|
Buffer.from(decodeEvmBytecodeCarrier(Buffer.from(text), "hex")).toString(
|
|
"hex",
|
|
),
|
|
).toBe("6000ff");
|
|
},
|
|
);
|
|
it.each(["0x1", "60 00", "0xzz", "\uFEFF6000", "\u00a06000"])(
|
|
"rejects malformed carrier rather than guessing bytecode: %j",
|
|
(text) => {
|
|
expect(() => decodeEvmBytecodeCarrier(Buffer.from(text), "hex")).toThrow(
|
|
EvmCarrierFailure,
|
|
);
|
|
},
|
|
);
|
|
it("rejects a long interior separator run without pathological backtracking", async () => {
|
|
const moduleUrl = new URL("./EvmBytecodeCarrier.ts", import.meta.url).href;
|
|
const source = `
|
|
import assert from "node:assert/strict";
|
|
import { decodeEvmBytecodeCarrier, EvmCarrierFailure } from ${JSON.stringify(moduleUrl)};
|
|
const text = "60" + " ".repeat(1_000_000) + "00";
|
|
assert.throws(() => decodeEvmBytecodeCarrier(Buffer.from(text), "hex"), EvmCarrierFailure);
|
|
`;
|
|
await promisify(execFile)(
|
|
process.execPath,
|
|
// tsx resolves the module's own `.js` imports to their TypeScript sources.
|
|
["--import", "tsx", "--input-type=module", "-e", source],
|
|
{
|
|
timeout: 15_000,
|
|
killSignal: "SIGKILL",
|
|
},
|
|
);
|
|
});
|
|
it("distinguishes raw bytes, empty code and malformed UTF-8", () => {
|
|
const bytes = Uint8Array.from([0xff, 0x00]);
|
|
const decoded = decodeEvmBytecodeCarrier(bytes, "raw");
|
|
expect(decoded).toEqual(bytes);
|
|
expect(decoded).not.toBe(bytes);
|
|
expect(() => decodeEvmBytecodeCarrier(bytes, "hex")).toThrow("valid UTF-8");
|
|
expect(decodeEvmBytecodeCarrier(Buffer.from("0x"), "hex")).toEqual(
|
|
new Uint8Array(),
|
|
);
|
|
});
|