SecurityException ("https://support.google.com/faqs/answer/9294009"); явно, когда мы сталкиваемся с "Zip Path Traversal уязвимость" . 11. < /p>
Код: Выделить всё
public static boolean extractZipFile(InputStream inputStream, String destDirectory, boolean overwrite) {
ZipInputStream zipInputStream = null;
boolean status = true;
try {
zipInputStream = new ZipInputStream(inputStream);
final byte[] data = new byte[1024];
while (true) {
ZipEntry zipEntry = null;
FileOutputStream outputStream = null;
try {
zipEntry = zipInputStream.getNextEntry();
if (zipEntry == null) {
break;
}
final File destination = new File(destDirectory, zipEntry.getName());
final String canonicalPath = destination.getCanonicalPath();
if (!canonicalPath.startsWith(destDirectory)) {
throw new SecurityException("https://support.google.com/faqs/answer/9294009");
}
Код: Выделить всё
public static boolean extractZipFile(InputStream inputStream, boolean overwrite) {
String destDirectory = Utils.getUserDataDirectory();
if (destDirectory == null) {
return false;
}
return extractZipFile(inputStream, destDirectory, overwrite);
}
public static String getUserDataDirectory() {
if (externalFilesDir == null) {
File _externalFilesDir = JStockApplication.instance().getExternalFilesDir(null);
externalFilesDir = _externalFilesDir;
if (externalFilesDir == null) {
return null;
}
}
return toEndWithFileSeperator(externalFilesDir.toString()) + getApplicationVersionString() + File.separator;
}
private static String toEndWithFileSeperator(String string) {
if (string.endsWith(File.separator)) {
return string;
}
return string + File.separator;
}
public static String getApplicationVersionString() {
return "1.0.7";
}
< /code>
На основании позиционированного исходного кода, есть ли у вас есть причина, почему «уязвимость прохождения Zip Path происходит только в Android 11? Я использую эмулятор Android 11, но не могу воспроизвести проблему. src = "https://i.sstatic.net/lsptg.png"/>
Мы используем следующий код для извлечения во время выполнения.
private void initPreloadDatabase(boolean overWrite) {
AssetManager assetManager = getResources().getAssets();
InputStream inputStream = null;
try {
inputStream = assetManager.open("database" + File.separator + "database.zip");
} catch (IOException e) {
Log.e(TAG, "", e);
}
if (inputStream != null) {
org.yccheok.jstock.gui.Utils.extractZipFile(inputStream, overWrite);
}
}
https://raw.githubusercontent.com/ycche ... stocks.zip
Подробнее здесь: https://stackoverflow.com/questions/695 ... happens-on