pxb1988/dex2jar · error · IOException
File too small to be a dex/zip
Error message
File too small to be a dex/zip
What it means
MultiDexFileReader.open(byte[]) throws IOException when the supplied byte array is shorter than 3 bytes, because at least 3 bytes are needed to distinguish a 'dex' magic prefix from a 'PK' zip prefix. The input cannot possibly be a dex or zip container, so it is rejected immediately.
Solutions
- Check the input file exists and is non-trivially sized before calling open().
- Re-download or re-extract the APK/dex artifact.
- Verify the byte array is filled (read fully from the stream, check return length).
- Log the data length at the call site to catch passing the wrong buffer.
Example fix
// before
BaseDexFileReader r = MultiDexFileReader.open(data);
// after
if (data == null || data.length < 3) {
throw new IllegalArgumentException("input too small to be dex/zip: " + (data == null ? -1 : data.length));
}
BaseDexFileReader r = MultiDexFileReader.open(data); Defensive patterns
Strategy: validation
Validate before calling
if (data == null || data.length < 3) {
throw new IllegalArgumentException("input bytes too small to be a dex/zip: " + (data == null ? "null" : data.length));
} Try / catch
try {
BaseDexFileReader r = MultiDexFileReader.open(data);
} catch (IOException e) {
LOG.error("input is not a dex/zip: " + e.getMessage());
} Prevention
- Check File.length() before reading into a byte array
- Fully consume streams (use readAllBytes/IOUtils) and verify non-empty
- Log the resolved path/size when loading APK or dex artifacts
When it happens
Trigger: Calling MultiDexFileReader.open(data) with data.length < 3, e.g. an empty array, a null-initialized buffer, or a truncated read of the APK/dex file.
Common situations: Reading an empty file from disk; a failed download that saved a 0-byte artifact; passing the wrong variable (an offset buffer or config string) instead of file contents.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- File too small to be a dex/zip
- Can not find classes.dex in zip file
- The source file is not a .dex or .zip file
- Can not find classes.dex in zip file
- the src file not a .dex or zip file
AI-assisted analysis of pxb1988/dex2jar@b5bda4fb49 (2026-09-08).
Data as JSON: /api/errors/6f532b27dde40e31.
Report an issue: GitHub.
Appendix: source
Thrown at dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java:34
final private List<Item> items = new ArrayList<>();
public MultiDexFileReader(Collection<DexFileReader> readers) {
this.readers.addAll(readers);
init();
}
private static byte[] toByteArray(InputStream is) throws IOException {
AccessBufByteArrayOutputStream out = new AccessBufByteArrayOutputStream();
byte[] buff = new byte[1024];
for (int c = is.read(buff); c > 0; c = is.read(buff)) {
out.write(buff, 0, c);
}
return out.getBuf();
}
public static BaseDexFileReader open(byte[] data) throws IOException {
if (data.length < 3) {
throw new IOException("File too small to be a dex/zip");
}
if ("dex".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex
return new DexFileReader(data);
} else if ("PK".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP
TreeMap<String, DexFileReader> dexFileReaders = new TreeMap<>();
try (ZipFile zipFile = new ZipFile(data)) {
for (ZipEntry e : zipFile.entries()) {
String entryName = e.getName();
if (entryName.startsWith("classes") && entryName.endsWith(".dex")) {
if (!dexFileReaders.containsKey(entryName)) { // only the first one
dexFileReaders.put(entryName, new DexFileReader(toByteArray(zipFile.getInputStream(e))));
}
}
}
}
if (dexFileReaders.size() == 0) {
throw new IOException("Can not find classes.dex in zip file");
} else if (dexFileReaders.size() == 1) {View on GitHub (pinned to b5bda4fb49)