mirror of
https://github.com/morluto/rea.git
synced 2026-11-07 23:36:41 +00:00
fix(frida): share exact JSON string byte accounting
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>
This commit is contained in:
1 parent
4cbcead46c
commit
435efe7afc
8 files changed
+191
-91
No files matched your search
@@ -0,0 +1,28 @@
|
||||
/** Exact UTF-8 bytes of a JSON string literal, counted without serializing it. */
|
||||
export const jsonStringByteLength = (value: string): number => {
|
||||
let bytes = 2;
|
||||
for (let index = 0; index < value.length; index++) {
|
||||
const unit = value.charCodeAt(index);
|
||||
if (unit === 0x22 || unit === 0x5c) bytes += 2;
|
||||
else if (unit < 0x20)
|
||||
bytes +=
|
||||
unit === 0x08 ||
|
||||
unit === 0x09 ||
|
||||
unit === 0x0a ||
|
||||
unit === 0x0c ||
|
||||
unit === 0x0d
|
||||
? 2
|
||||
: 6;
|
||||
else if (unit < 0x80) bytes += 1;
|
||||
else if (unit < 0x800) bytes += 2;
|
||||
else if (unit >= 0xd800 && unit <= 0xdbff) {
|
||||
const next = value.charCodeAt(index + 1);
|
||||
if (next >= 0xdc00 && next <= 0xdfff) {
|
||||
bytes += 4;
|
||||
index++;
|
||||
} else bytes += 6;
|
||||
} else if (unit >= 0xdc00 && unit <= 0xdfff) bytes += 6;
|
||||
else bytes += 3;
|
||||
}
|
||||
return bytes;
|
||||
};
|
||||
Reference in new issue
Block a user