mirror of
https://github.com/revanced/Apktool.git
synced 2025-05-01 22:54:24 +02:00
fix: skip files that violate safe filepath
This commit is contained in:
parent
49a167540f
commit
98aa7acb22
@ -22,6 +22,9 @@ import brut.androlib.res.AndrolibResources;
|
|||||||
import brut.androlib.res.data.ResPackage;
|
import brut.androlib.res.data.ResPackage;
|
||||||
import brut.androlib.res.data.ResTable;
|
import brut.androlib.res.data.ResTable;
|
||||||
import brut.androlib.res.data.ResUnknownFiles;
|
import brut.androlib.res.data.ResUnknownFiles;
|
||||||
|
import brut.common.InvalidUnknownFileException;
|
||||||
|
import brut.common.RootUnknownFileException;
|
||||||
|
import brut.common.TraversalUnknownFileException;
|
||||||
import brut.directory.ExtFile;
|
import brut.directory.ExtFile;
|
||||||
import brut.androlib.res.xml.ResXmlPatcher;
|
import brut.androlib.res.xml.ResXmlPatcher;
|
||||||
import brut.androlib.src.SmaliBuilder;
|
import brut.androlib.src.SmaliBuilder;
|
||||||
@ -663,7 +666,15 @@ public class Androlib {
|
|||||||
|
|
||||||
// loop through unknown files
|
// loop through unknown files
|
||||||
for (Map.Entry<String,String> unknownFileInfo : files.entrySet()) {
|
for (Map.Entry<String,String> unknownFileInfo : files.entrySet()) {
|
||||||
File inputFile = new File(unknownFileDir, BrutIO.sanitizeUnknownFile(unknownFileDir, unknownFileInfo.getKey()));
|
File inputFile;
|
||||||
|
|
||||||
|
try {
|
||||||
|
inputFile = new File(unknownFileDir, BrutIO.sanitizeUnknownFile(unknownFileDir, unknownFileInfo.getKey()));
|
||||||
|
} catch (RootUnknownFileException | InvalidUnknownFileException | TraversalUnknownFileException exception) {
|
||||||
|
LOGGER.warning(String.format("Skipping file %s (%s)", unknownFileInfo.getKey(), exception.getMessage()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (inputFile.isDirectory()) {
|
if (inputFile.isDirectory()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,20 @@
|
|||||||
package brut.directory;
|
package brut.directory;
|
||||||
|
|
||||||
import brut.common.BrutException;
|
import brut.common.BrutException;
|
||||||
|
import brut.common.InvalidUnknownFileException;
|
||||||
|
import brut.common.RootUnknownFileException;
|
||||||
|
import brut.common.TraversalUnknownFileException;
|
||||||
import brut.util.BrutIO;
|
import brut.util.BrutIO;
|
||||||
import brut.util.OS;
|
import brut.util.OS;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
* @author Ryszard Wiśniewski <brut.alll@gmail.com>
|
||||||
*/
|
*/
|
||||||
public class DirUtil {
|
public class DirUtil {
|
||||||
|
private static final Logger LOGGER = Logger.getLogger("");
|
||||||
|
|
||||||
public static void copyToDir(Directory in, Directory out)
|
public static void copyToDir(Directory in, Directory out)
|
||||||
throws DirectoryException {
|
throws DirectoryException {
|
||||||
for (String fileName : in.getFiles(true)) {
|
for (String fileName : in.getFiles(true)) {
|
||||||
@ -84,15 +90,12 @@ public class DirUtil {
|
|||||||
String cleanedFilename = BrutIO.sanitizeUnknownFile(out, fileName);
|
String cleanedFilename = BrutIO.sanitizeUnknownFile(out, fileName);
|
||||||
File outFile = new File(out, cleanedFilename);
|
File outFile = new File(out, cleanedFilename);
|
||||||
outFile.getParentFile().mkdirs();
|
outFile.getParentFile().mkdirs();
|
||||||
BrutIO.copyAndClose(in.getFileInput(fileName),
|
BrutIO.copyAndClose(in.getFileInput(fileName), new FileOutputStream(outFile));
|
||||||
new FileOutputStream(outFile));
|
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (RootUnknownFileException | InvalidUnknownFileException | TraversalUnknownFileException exception) {
|
||||||
throw new DirectoryException(
|
LOGGER.warning(String.format("Skipping file %s (%s)", fileName, exception.getMessage()));
|
||||||
"Error copying file: " + fileName, ex);
|
} catch (IOException | BrutException ex) {
|
||||||
} catch (BrutException ex) {
|
throw new DirectoryException("Error copying file: " + fileName, ex);
|
||||||
throw new DirectoryException(
|
|
||||||
"Error copying file: " + fileName, ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user