Skip to content

Commit 2d28da9

Browse files
committed
feat: allow to set zip max entries count using env var (#1751)
1 parent edb1717 commit 2d28da9

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ Plugin options (-P<name>=<value>):
173173
- rename-mappings.format - mapping format, values: [auto, TINY, TINY_2, ENIGMA, ENIGMA_DIR, MCP, SRG, TSRG, TSRG2, PROGUARD], default: auto
174174
- rename-mappings.invert - invert mapping, values: [yes, no], default: no
175175

176+
Environment variables:
177+
JADX_DISABLE_ZIP_SECURITY - set to 'true' to disable all security checks for zip files
178+
JADX_ZIP_MAX_ENTRIES_COUNT - maximum allowed number of entries in zip files (default: 100 000)
179+
JADX_TMP_DIR - custom temp directory, using system by default
180+
176181
Examples:
177182
jadx -d out classes.dex
178183
jadx --rename-flags "none" classes.dex

jadx-cli/src/main/java/jadx/cli/JCommanderWrapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public void printUsage() {
108108
int maxNamesLen = printOptions(jc, out, true);
109109
out.println(appendPluginOptions(maxNamesLen));
110110
out.println();
111+
out.println("Environment variables:");
112+
out.println(" JADX_DISABLE_ZIP_SECURITY - set to 'true' to disable all security checks for zip files");
113+
out.println(" JADX_ZIP_MAX_ENTRIES_COUNT - maximum allowed number of entries in zip files (default: 100 000)");
114+
out.println(" JADX_TMP_DIR - custom temp directory, using system by default");
115+
out.println();
111116
out.println("Examples:");
112117
out.println(" jadx -d out classes.dex");
113118
out.println(" jadx --rename-flags \"none\" classes.dex");

jadx-core/src/main/java/jadx/api/plugins/utils/ZipSecurity.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.io.IOException;
66
import java.io.InputStream;
77
import java.util.Enumeration;
8-
import java.util.Objects;
98
import java.util.function.BiConsumer;
109
import java.util.function.BiFunction;
1110
import java.util.zip.ZipEntry;
@@ -15,10 +14,13 @@
1514
import org.slf4j.Logger;
1615
import org.slf4j.LoggerFactory;
1716

17+
import jadx.core.utils.Utils;
18+
import jadx.core.utils.exceptions.JadxRuntimeException;
19+
1820
public class ZipSecurity {
1921
private static final Logger LOG = LoggerFactory.getLogger(ZipSecurity.class);
2022

21-
private static final boolean DISABLE_CHECKS = Objects.equals(System.getenv("JADX_DISABLE_ZIP_SECURITY"), "true");
23+
private static final boolean DISABLE_CHECKS = Utils.getEnvVarBool("JADX_DISABLE_ZIP_SECURITY", false);
2224

2325
/**
2426
* size of uncompressed zip entry shouldn't be bigger of compressed in
@@ -31,7 +33,8 @@ public class ZipSecurity {
3133
* are considered safe
3234
*/
3335
private static final int ZIP_BOMB_MIN_UNCOMPRESSED_SIZE = 25 * 1024 * 1024;
34-
private static final int MAX_ENTRIES_COUNT = 100_000;
36+
37+
private static final int MAX_ENTRIES_COUNT = Utils.getEnvVarInt("JADX_ZIP_MAX_ENTRIES_COUNT", 100_000);
3538

3639
private ZipSecurity() {
3740
}
@@ -130,13 +133,13 @@ public static <R> R visitZipEntries(File file, BiFunction<ZipFile, ZipEntry, R>
130133
}
131134
entriesProcessed++;
132135
if (!DISABLE_CHECKS && entriesProcessed > MAX_ENTRIES_COUNT) {
133-
throw new IllegalStateException("Zip entries count limit exceeded: " + MAX_ENTRIES_COUNT
136+
throw new JadxRuntimeException("Zip entries count limit exceeded: " + MAX_ENTRIES_COUNT
134137
+ ", last entry: " + entry.getName());
135138
}
136139
}
137140
}
138141
} catch (Exception e) {
139-
throw new RuntimeException("Failed to process zip file: " + file.getAbsolutePath(), e);
142+
throw new JadxRuntimeException("Failed to process zip file: " + file.getAbsolutePath(), e);
140143
}
141144
return null;
142145
}
@@ -147,7 +150,7 @@ public static void readZipEntries(File file, BiConsumer<ZipEntry, InputStream> v
147150
try (InputStream in = getInputStreamForEntry(zip, entry)) {
148151
visitor.accept(entry, in);
149152
} catch (Exception e) {
150-
throw new RuntimeException("Error process zip entry: " + entry.getName());
153+
throw new JadxRuntimeException("Failed to process zip entry: " + entry.getName());
151154
}
152155
}
153156
return null;

jadx-core/src/main/java/jadx/core/utils/Utils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,20 @@ public static void checkThreadInterrupt() {
487487
throw new JadxRuntimeException("Thread interrupted");
488488
}
489489
}
490+
491+
public static boolean getEnvVarBool(String varName, boolean defValue) {
492+
String strValue = System.getenv(varName);
493+
if (strValue == null) {
494+
return defValue;
495+
}
496+
return strValue.equalsIgnoreCase("true");
497+
}
498+
499+
public static int getEnvVarInt(String varName, int defValue) {
500+
String strValue = System.getenv(varName);
501+
if (strValue == null) {
502+
return defValue;
503+
}
504+
return Integer.parseInt(strValue);
505+
}
490506
}

0 commit comments

Comments
 (0)