From d1eb175e88e8c542a44aa3280f53b96ac32e6bba Mon Sep 17 00:00:00 2001 From: BONNe Date: Sun, 2 Jan 2022 03:45:05 +0200 Subject: [PATCH] Change AbsolutePath to CanonicalPath (#1901) I am not 100% sure if this would fix https://github.com/BentoBoxWorld/BSkyBlock/issues/451 However, searching google I found that others had a similar issue with the absolute path and they changed it to canonical. As I was not able to reproduce the main reported issue, I do not know if this fixes it. --- .../bentobox/managers/BlueprintClipboardManager.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/BlueprintClipboardManager.java b/src/main/java/world/bentobox/bentobox/managers/BlueprintClipboardManager.java index cc7ea3c16..60e589a3c 100644 --- a/src/main/java/world/bentobox/bentobox/managers/BlueprintClipboardManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/BlueprintClipboardManager.java @@ -96,7 +96,7 @@ public class BlueprintClipboardManager { plugin.logError(LOAD_ERROR + zipFile.getName()); throw new IOException(LOAD_ERROR + zipFile.getName()); } - unzip(zipFile.getAbsolutePath()); + unzip(zipFile.getCanonicalPath()); File file = new File(blueprintFolder, BlueprintsManager.sanitizeFileName(fileName)); if (!file.exists()) { plugin.logError(LOAD_ERROR + file.getName()); @@ -194,7 +194,7 @@ public class BlueprintClipboardManager { if (!entry.isDirectory()) { unzipFiles(zipInputStream, filePath); } else { - if (!filePath.startsWith(blueprintFolder.getAbsolutePath())) { + if (!filePath.startsWith(blueprintFolder.getCanonicalPath())) { throw new IOException("Entry is outside of the target directory"); } Files.createDirectories(filePath); @@ -207,10 +207,10 @@ public class BlueprintClipboardManager { } private void unzipFiles(final ZipInputStream zipInputStream, final Path unzipFilePath) throws IOException { - if (!unzipFilePath.toAbsolutePath().toString().startsWith(blueprintFolder.getAbsolutePath())) { + if (!unzipFilePath.toFile().getCanonicalPath().startsWith(blueprintFolder.getCanonicalPath())) { throw new IOException("Entry is outside of the target directory"); } - try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(unzipFilePath.toAbsolutePath().toString()))) { + try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(unzipFilePath.toFile().getCanonicalPath()))) { byte[] bytesIn = new byte[1024]; int read; while ((read = zipInputStream.read(bytesIn)) != -1) { @@ -220,7 +220,7 @@ public class BlueprintClipboardManager { } private void zip(File targetFile) throws IOException { - try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(targetFile.getAbsolutePath() + BlueprintsManager.BLUEPRINT_SUFFIX))) { + try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(targetFile.getCanonicalPath() + BlueprintsManager.BLUEPRINT_SUFFIX))) { zipOutputStream.putNextEntry(new ZipEntry(targetFile.getName())); try (FileInputStream inputStream = new FileInputStream(targetFile)) { final byte[] buffer = new byte[1024];