From 2a7db7313a5c69c551585b8362fc4e0522e0f3b7 Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Sat, 26 Oct 2024 03:16:40 +0000 Subject: [PATCH] Modernize and secure temp file creation --- .../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 3c5753f027f..de548881e27 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.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 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); 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 12cd5204fbf..e32c1375d4e 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.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import javax.imageio.ImageIO; @@ -30,7 +31,7 @@ public InvertFullColorStrategy(MultipartFile file, ReplaceAndInvert replaceAndIn 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);