fix(cli): stream JSON inputs beyond the whole-document string limit (#1360)

Stream large CLI JSON files through a strict UTF-8 decoder and standard JSON parser using the same admitted regular-file handle. Preserve native parsing for small inputs, typed malformed-input/resource/access-denied errors, cancellation, and complete Evidence.

Verified with focused public CLI regressions, a 768 MB whitespace-padded valid request, and the Windows native decoder boundary. Individual strings and the assembled object graph remain subject to native runtime limits. All 27 final-head checks passed.

Refs #1331
This commit is contained in:
Ysopwnable
2026-10-10 04:53:09 +08:00
committed by GitHub
parent 3728c8267b
commit 6ce3288f3b
10 changed files with 555 additions and 197 deletions
+18 -5
View File
@@ -1,16 +1,29 @@
import type { Stats } from "node:fs";
import type { FileHandle } from "node:fs/promises";
import { openRegularFile } from "../filesystem/RegularFile.js";
/** Admit a regular file without waiting for a pipe, then read its verified handle. */
export const readRegularFile = async (
/** Admit one regular-file handle, retain it through the consumer, and always close it. */
export const withRegularFile = async <Value>(
path: string,
read: (handle: FileHandle, stats: Stats) => Promise<Value>,
signal?: AbortSignal,
): Promise<Buffer> => {
): Promise<Value> => {
const handle = await openRegularFile(path, { symlinks: "follow", signal });
try {
const bytes = await handle.readFile({ signal });
const stats = await handle.stat();
signal?.throwIfAborted();
return bytes;
const value = await read(handle, stats);
signal?.throwIfAborted();
return value;
} finally {
await handle.close();
}
};
/** Admit a regular file without waiting for a pipe, then read its verified handle. */
export const readRegularFile = (
path: string,
signal?: AbortSignal,
): Promise<Buffer> =>
withRegularFile(path, (handle) => handle.readFile({ signal }), signal);