Skip to content

Commit 4fd35f6

Browse files
committed
Improve canonical path handling in DecompressFile
1 parent 4e31f16 commit 4fd35f6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

baremaps-core/src/main/java/org/apache/baremaps/tasks/DecompressFile.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ public static void decompressTar(Path target, TarArchiveInputStream tarInputStre
162162
File destination = target.resolve(entry.getName()).normalize().toFile();
163163
String canonicalDestinationPath = destination.getCanonicalPath();
164164
String canonicalTargetPath = target.toFile().getCanonicalPath();
165+
if (!canonicalTargetPath.endsWith(File.separator)) {
166+
canonicalTargetPath += File.separator;
167+
}
165168
if (canonicalDestinationPath.startsWith(canonicalTargetPath)) {
166169
if (entry.isDirectory()) {
167170
Files.createDirectories(destination.toPath());
@@ -196,7 +199,9 @@ protected static void decompressZip(Path source, Path target) throws IOException
196199
File destination = target.resolve(entry.getName()).normalize().toFile();
197200
String canonicalDestinationPath = destination.getCanonicalPath();
198201
String canonicalTargetPath = target.toFile().getCanonicalPath();
199-
202+
if (!canonicalTargetPath.endsWith(File.separator)) {
203+
canonicalTargetPath += File.separator;
204+
}
200205
if (canonicalDestinationPath.startsWith(canonicalTargetPath)) {
201206
if (entry.isDirectory()) {
202207
Files.createDirectories(destination.toPath());

0 commit comments

Comments
 (0)