Merge branch '2.4.x'
Closes gh-25509
This commit is contained in:
@@ -29,7 +29,6 @@ import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The {@code 'extract'} tools command.
|
||||
@@ -86,15 +85,18 @@ class ExtractCommand extends Command {
|
||||
}
|
||||
|
||||
private void write(ZipInputStream zip, ZipEntry entry, File destination) throws IOException {
|
||||
String path = StringUtils.cleanPath(entry.getName());
|
||||
File file = new File(destination, path);
|
||||
if (file.getAbsolutePath().startsWith(destination.getAbsolutePath())) {
|
||||
mkParentDirs(file);
|
||||
try (OutputStream out = new FileOutputStream(file)) {
|
||||
StreamUtils.copy(zip, out);
|
||||
}
|
||||
Files.setAttribute(file.toPath(), "creationTime", entry.getCreationTime());
|
||||
String canonicalOutputPath = destination.getCanonicalPath() + File.separator;
|
||||
File file = new File(destination, entry.getName());
|
||||
String canonicalEntryPath = file.getCanonicalPath();
|
||||
Assert.state(canonicalEntryPath.startsWith(canonicalOutputPath),
|
||||
() -> "Entry '" + entry.getName() + "' would be written to '" + canonicalEntryPath
|
||||
+ "'. This is outside the output location of '" + canonicalOutputPath
|
||||
+ "'. Verify the contents of your archive.");
|
||||
mkParentDirs(file);
|
||||
try (OutputStream out = new FileOutputStream(file)) {
|
||||
StreamUtils.copy(zip, out);
|
||||
}
|
||||
Files.setAttribute(file.toPath(), "creationTime", entry.getCreationTime());
|
||||
}
|
||||
|
||||
private void mkParentDirs(File file) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user