* Bounded full-file read for every whole-file path (view, edits, UI read, * save compare). Memory files can be edited outside MemoryService write caps, * so an unbounded read of a degenerate file could hang the main process or * blow up the stream context. Reads at most cap+1 bytes and reje
(
store: MemoryStore,
relPath: string,
virtualPath: string
)
| 881 | * and the bytes must be read first). |
| 882 | */ |
| 883 | private async readBoundedTextFile( |
| 884 | store: MemoryStore, |
| 885 | relPath: string, |
| 886 | virtualPath: string |
| 887 | ): Promise<string> { |
| 888 | const content = await store.readFilePrefix(relPath, MEMORY_MAX_FILE_BYTES + 1); |
| 889 | if (Buffer.byteLength(content, "utf-8") > MEMORY_MAX_FILE_BYTES) { |
| 890 | throw new MemoryCommandError( |
| 891 | `${virtualPath} exceeds the ${MEMORY_MAX_FILE_BYTES}-byte memory file cap (likely edited outside Mux, bypassing write caps); shrink or delete it` |
| 892 | ); |
| 893 | } |
| 894 | return content; |
| 895 | } |
| 896 | |
| 897 | private async readTextFileForEdit( |
| 898 | store: MemoryStore, |
no test coverage detected