Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize and secure temp file creation #2106

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down