mirror of
https://github.com/morluto/rea
synced 2026-10-26 14:25:49 -04:00
435efe7afc
Count the serialized JSON representation at its owner, including escaped lone UTF-16 surrogates. Frida now retains the correct bounded prefix and reports truncation in script results and subsequent session Evidence. Move the existing exact managed string counter into the domain layer and use it for Frida, managed projections and Ghidra inline PDB caveats. Remove the superseded counters while keeping Ghidra's bounded length guards and NativeAOT's distinct raw-byte admission before string allocation. Validated with 296 focused tests, check, docs and exact test discovery. The Unicode oracle checks every UTF-16 code unit and adjacent fragments against native JSON encoding. Frida execution uses simulated native handles through the real MCP handlers/client; real target instrumentation is unverified. Fixes #5097 Co-authored-by: Prabhuram Karki <prabhuramkarki07@gmail.com>
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import { jsonStringByteLength } from "./jsonStringByteLength.js";
|
|
|
|
it("matches native JSON encoding for every individual UTF-16 code unit", () => {
|
|
const mismatches: number[] = [];
|
|
for (let unit = 0; unit <= 0xffff; unit += 1) {
|
|
const value = String.fromCharCode(unit);
|
|
if (
|
|
jsonStringByteLength(value) !== Buffer.byteLength(JSON.stringify(value))
|
|
)
|
|
mismatches.push(unit);
|
|
}
|
|
expect(mismatches).toEqual([]);
|
|
});
|
|
|
|
it("counts adjacent surrogates, escapes and multibyte text as native JSON encodes them", () => {
|
|
const fragments = [
|
|
"",
|
|
"a",
|
|
"\u0000",
|
|
"\b\t\n\f\r",
|
|
'"\\',
|
|
"é",
|
|
"€",
|
|
"\ud7ff",
|
|
"\ue000",
|
|
"\ud800",
|
|
"\udbff",
|
|
"\udc00",
|
|
"\udfff",
|
|
"😀",
|
|
];
|
|
const mismatches: string[] = [];
|
|
for (const left of fragments)
|
|
for (const right of fragments) {
|
|
const value = left + right;
|
|
if (
|
|
jsonStringByteLength(value) !== Buffer.byteLength(JSON.stringify(value))
|
|
)
|
|
mismatches.push(value);
|
|
}
|
|
expect(mismatches).toEqual([]);
|
|
});
|