This commit is contained in:
teresa 2025-06-19 20:16:22 +07:00 committed by GitHub
commit 3b5ebff1ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View file

@ -502,7 +502,7 @@ public class PersistenceManager<T extends PersistableEnvelope> {
tempFile = usedTempFilePath != null
? FileUtil.createNewFile(usedTempFilePath)
: File.createTempFile("temp_" + fileName, null, dir);
: Files.createTempFile(dir.toPath(), "temp_" + fileName, null).toFile();
// Don't use a new temp file path each time, as that causes the delete-on-exit hook to leak memory:
tempFile.deleteOnExit();

View file

@ -104,6 +104,10 @@ public class ZipUtils {
int count;
while ((entry = zipStream.getNextEntry()) != null) {
File file = new File(dir, entry.getName());
if (!file.toPath().normalize().startsWith(dir.toPath())) {
throw new SecurityException("ZIP entry contains path traversal attempt: " + entry.getName());
}
if (entry.isDirectory()) {
file.mkdirs();
} else {