From af5e2b6895397bddc3ac78e66ba763fad9b54d02 Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:19:12 +0000 Subject: [PATCH] Modernize and secure temp file creation (#2106) Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com> --- .../software/SPDF/utils/misc/CustomColorReplaceStrategy.java | 3 ++- .../software/SPDF/utils/misc/InvertFullColorStrategy.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/utils/misc/CustomColorReplaceStrategy.java b/src/main/java/stirling/software/SPDF/utils/misc/CustomColorReplaceStrategy.java index 3c5753f0..de548881 100644 --- a/src/main/java/stirling/software/SPDF/utils/misc/CustomColorReplaceStrategy.java +++ b/src/main/java/stirling/software/SPDF/utils/misc/CustomColorReplaceStrategy.java @@ -5,6 +5,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.util.List; import java.util.Set; @@ -53,7 +54,7 @@ public class CustomColorReplaceStrategy extends ReplaceAndInvertColorStrategy { } // Create a temporary file, with the original filename from the multipart file - File file = File.createTempFile("temp", getFileInput().getOriginalFilename()); + File file = Files.createTempFile("temp", getFileInput().getOriginalFilename()).toFile(); // Transfer the content of the multipart file to the file getFileInput().transferTo(file); diff --git a/src/main/java/stirling/software/SPDF/utils/misc/InvertFullColorStrategy.java b/src/main/java/stirling/software/SPDF/utils/misc/InvertFullColorStrategy.java index 12cd5204..e32c1375 100644 --- a/src/main/java/stirling/software/SPDF/utils/misc/InvertFullColorStrategy.java +++ b/src/main/java/stirling/software/SPDF/utils/misc/InvertFullColorStrategy.java @@ -6,6 +6,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import javax.imageio.ImageIO; @@ -30,7 +31,7 @@ public class InvertFullColorStrategy extends ReplaceAndInvertColorStrategy { public InputStreamResource replace() throws IOException { // Create a temporary file, with the original filename from the multipart file - File file = File.createTempFile("temp", getFileInput().getOriginalFilename()); + File file = Files.createTempFile("temp", getFileInput().getOriginalFilename()).toFile(); // Transfer the content of the multipart file to the file getFileInput().transferTo(file);