From d1434d1c808038673c9bb2695f60a9b05eec49b0 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 10 Aug 2025 20:57:12 -0700 Subject: [PATCH] [backport 1.25] Add bounds checking for clipspace indices to prevent paste errors (core/1.25 backport) (#4904) --- src/extensions/core/maskeditor.ts | 18 ++++++++++++------ src/scripts/app.ts | 11 +++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/extensions/core/maskeditor.ts b/src/extensions/core/maskeditor.ts index c07a3d84d..f07954863 100644 --- a/src/extensions/core/maskeditor.ts +++ b/src/extensions/core/maskeditor.ts @@ -3976,13 +3976,19 @@ class UIManager { const mainImageFilename = new URL(mainImageUrl).searchParams.get('filename') ?? undefined - const combinedImageFilename = + let combinedImageFilename: string | null | undefined + if ( ComfyApp.clipspace?.combinedIndex !== undefined && - ComfyApp.clipspace?.imgs?.[ComfyApp.clipspace.combinedIndex]?.src - ? new URL( - ComfyApp.clipspace.imgs[ComfyApp.clipspace.combinedIndex].src - ).searchParams.get('filename') - : undefined + ComfyApp.clipspace?.imgs && + ComfyApp.clipspace.combinedIndex < ComfyApp.clipspace.imgs.length && + ComfyApp.clipspace.imgs[ComfyApp.clipspace.combinedIndex]?.src + ) { + combinedImageFilename = new URL( + ComfyApp.clipspace.imgs[ComfyApp.clipspace.combinedIndex].src + ).searchParams.get('filename') + } else { + combinedImageFilename = undefined + } const imageLayerFilenames = mainImageFilename !== undefined diff --git a/src/scripts/app.ts b/src/scripts/app.ts index 2baed3618..8c27aa44a 100644 --- a/src/scripts/app.ts +++ b/src/scripts/app.ts @@ -385,8 +385,15 @@ export class ComfyApp { static pasteFromClipspace(node: LGraphNode) { if (ComfyApp.clipspace) { // image paste - const combinedImgSrc = - ComfyApp.clipspace.imgs?.[ComfyApp.clipspace.combinedIndex].src + let combinedImgSrc: string | undefined + if ( + ComfyApp.clipspace.combinedIndex !== undefined && + ComfyApp.clipspace.imgs && + ComfyApp.clipspace.combinedIndex < ComfyApp.clipspace.imgs.length + ) { + combinedImgSrc = + ComfyApp.clipspace.imgs[ComfyApp.clipspace.combinedIndex].src + } if (ComfyApp.clipspace.imgs && node.imgs) { if (node.images && ComfyApp.clipspace.images) { if (ComfyApp.clipspace['img_paste_mode'] == 'selected') {