From 3a6172bea2d95758472570b156b001d5cf4da442 Mon Sep 17 00:00:00 2001 From: Christian Schulz Date: Fri, 30 May 2025 17:21:32 +0200 Subject: [PATCH] Fix: Evaluate LoadDrawablesFromStream() before disposing the stream Break after a container is found --- src/Greenshot.Base/Core/ClipboardHelper.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Greenshot.Base/Core/ClipboardHelper.cs b/src/Greenshot.Base/Core/ClipboardHelper.cs index bfe13c121..789feb417 100644 --- a/src/Greenshot.Base/Core/ClipboardHelper.cs +++ b/src/Greenshot.Base/Core/ClipboardHelper.cs @@ -610,6 +610,7 @@ EndSelection:<<<<<<<4 } var fileFormatHandlers = SimpleServiceProvider.Current.GetAllInstances(); var supportedExtensions = fileFormatHandlers.ExtensionsFor(FileFormatHandlerActions.LoadDrawableFromStream).ToList(); + var foundContainer = false; foreach (var (stream, filename) in IterateClipboardContent(dataObject)) { @@ -622,7 +623,8 @@ EndSelection:<<<<<<<4 IEnumerable drawableContainers; try { - drawableContainers = fileFormatHandlers.LoadDrawablesFromStream(stream, extension); + // without toList() here, LoadDrawablesFromStream() are called after the stream has been disposed + drawableContainers = fileFormatHandlers.LoadDrawablesFromStream(stream, extension).ToList(); } catch (Exception ex) { @@ -636,10 +638,14 @@ EndSelection:<<<<<<<4 // If we get here, there is an image foreach (var container in drawableContainers) { + foundContainer = true; yield return container; } } + // we found sth., prevent multiple imports of the same content + if (foundContainer) yield break; + // check if files are supplied foreach (string imageFile in GetImageFilenames(dataObject)) {