diff --git a/third_party/java/proguard/proguard6.2.2/src/proguard/io/DirectoryWriter.java b/third_party/java/proguard/proguard6.2.2/src/proguard/io/DirectoryWriter.java index 35f29745d7dfc8..876a5377c32400 100644 --- a/third_party/java/proguard/proguard6.2.2/src/proguard/io/DirectoryWriter.java +++ b/third_party/java/proguard/proguard6.2.2/src/proguard/io/DirectoryWriter.java @@ -106,13 +106,22 @@ public void println(PrintWriter pw, String prefix) /** * Returns the file for the given data entry. */ - private File getFile(DataEntry dataEntry) + private File getFile(DataEntry dataEntry) throws IOException { // Use the specified file, or construct a new file. - return isFile ? + File file = isFile ? baseFile : new File(baseFile, dataEntry.getName().replace(ClassConstants.PACKAGE_SEPARATOR, File.separatorChar)); + + // Validate that the file path is within the base directory. + File canonicalBase = baseFile.getCanonicalFile(); + File canonicalFile = file.getCanonicalFile(); + if (!canonicalFile.toPath().startsWith(canonicalBase.toPath())) { + throw new IOException("Invalid entry: " + dataEntry.getName()); + } + + return file; } }