fix(input): validate escaped text against the actual command budget

The editor could clear 2048 quote characters although escaping exceeded the Native 4096-byte command budget. Measure the complete command before sending and retain oversized text. Core, Native and Browser use the 8192-byte UTF-8 carrier bound; independent queue budgets keep their own names. Static Browser values are compared with compiled Core, with no new WASM hot-path dependency. Real WebCrypto boundary probes, Native compilation and all 2521 Web tests pass.
This commit is contained in:
AAA committed 2026-11-27 00:59:56 -05:00
1 parent ec34b77aec
commit aa4e6ee45c
14 files changed
+65 -17

No files matched your search

+15 -1
View File
@@ -1,8 +1,22 @@
import { z } from "zod";
import { isComposingOrAltGraph } from "../ui/shortcut-key";
// A text submission still fits one encrypted input packet and the existing queue.
export const INPUT_FRAME_BYTES = 8192;
export const REMOTE_INPUT_COMMAND_BYTES = 4096;
export const REMOTE_TEXT_BYTES = 2048;
const encoder = new TextEncoder();
export function inputFrameFits(frame: string): boolean {
return frame.length <= INPUT_FRAME_BYTES && encoder.encode(frame).byteLength <= INPUT_FRAME_BYTES;
}
// The editor can measure the command before sending. Every grant has the same hex length.
const exampleGrant = "0".repeat(64);
export function remoteTextFits(text: string, grant = exampleGrant): boolean {
return text.length <= REMOTE_TEXT_BYTES && encoder.encode(text).byteLength <= REMOTE_TEXT_BYTES
&& encoder.encode(JSON.stringify({ type: "text", text, grant })).byteLength <= REMOTE_INPUT_COMMAND_BYTES;
}
// F12 is reserved by Windows debuggers, including for global modified chords.
export const remoteShortcutKeySchema = z.number().int().min(1).max(11);
export const REMOTE_SHORTCUT_KEYS = Array.from({ length: 11 }, (_, index) => index + 1);