diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/util/UnknownDirectoryTraversalTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/util/UnknownDirectoryTraversalTest.java index 1541353f..60d5c9e7 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/util/UnknownDirectoryTraversalTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/util/UnknownDirectoryTraversalTest.java @@ -71,6 +71,18 @@ public class UnknownDirectoryTraversalTest extends BaseTest { BrutIO.sanitizeUnknownFile(sTmpDir, ""); } + @Test(expected = TraversalUnknownFileException.class) + public void invalidBackwardPathOnWindows() throws IOException, BrutException { + String invalidPath; + if (! OSDetection.isWindows()) { + invalidPath = "../../app"; + } else { + invalidPath = "..\\..\\app.exe"; + } + + BrutIO.sanitizeUnknownFile(sTmpDir, invalidPath); + } + @Test public void validDirectoryFileTest() throws IOException, BrutException { String validFilename = BrutIO.sanitizeUnknownFile(sTmpDir, "dir" + File.separator + "file"); diff --git a/brut.j.dir/src/main/java/brut/directory/DirUtil.java b/brut.j.dir/src/main/java/brut/directory/DirUtil.java index bf4758d7..f06cb2c5 100644 --- a/brut.j.dir/src/main/java/brut/directory/DirUtil.java +++ b/brut.j.dir/src/main/java/brut/directory/DirUtil.java @@ -81,7 +81,8 @@ public class DirUtil { if (fileName.equals("res") && !in.containsFile(fileName)) { return; } - File outFile = new File(out, fileName); + String cleanedFilename = BrutIO.sanitizeUnknownFile(out, fileName); + File outFile = new File(out, cleanedFilename); outFile.getParentFile().mkdirs(); BrutIO.copyAndClose(in.getFileInput(fileName), new FileOutputStream(outFile));