fix: cap terminal paste size to 1MB to prevent GPU context exhaustion

Large clipboard pastes can cause GPU memory pressure when multiple
terminals are rendering simultaneously, leading to app crashes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
AndyMik90
2026-02-14 14:33:26 +01:00
parent 3a7c4ca7a9
commit 7b0f3a2c03
@@ -139,11 +139,18 @@ export function useXterm({ terminalId, onCommandEnter, onResize, onDimensionsRea
};
// Helper function to handle paste from clipboard
// Cap paste size to prevent GPU/memory pressure from extremely large clipboard contents.
const MAX_PASTE_BYTES = 1_048_576; // 1 MB
const handlePasteFromClipboard = (): void => {
navigator.clipboard.readText()
.then((text) => {
if (text) {
xterm.paste(text);
if (text.length > MAX_PASTE_BYTES) {
console.warn(`[useXterm] Paste truncated from ${text.length} to ${MAX_PASTE_BYTES} bytes`);
xterm.paste(text.slice(0, MAX_PASTE_BYTES));
} else {
xterm.paste(text);
}
}
})
.catch((err) => {