{"record":{"id":"d48df5c2579f192d","repo":"pxb1988/dex2jar","slug":"the-source-file-is-not-a-dex-or-zip-file","errorCode":null,"errorMessage":"The source file is not a .dex or .zip file","messagePattern":"The source file is not a \\.dex or \\.zip file","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java","lineNumber":58,"sourceCode":"            try (ZipFile zipFile = new ZipFile(data)) {\n                for (ZipEntry e : zipFile.entries()) {\n                    String entryName = e.getName();\n                    if (entryName.startsWith(\"classes\") && entryName.endsWith(\".dex\")) {\n                        if (!dexFileReaders.containsKey(entryName)) { // only the first one\n                            dexFileReaders.put(entryName, new DexFileReader(toByteArray(zipFile.getInputStream(e))));\n                        }\n                    }\n                }\n            }\n            if (dexFileReaders.size() == 0) {\n                throw new IOException(\"Can not find classes.dex in zip file\");\n            } else if (dexFileReaders.size() == 1) {\n                return dexFileReaders.firstEntry().getValue();\n            } else {\n                return new MultiDexFileReader(dexFileReaders.values());\n            }\n        }\n        throw new IOException(\"The source file is not a .dex or .zip file\");\n    }\n\n    void init() {\n        Set<String> classes = new HashSet<>();\n        for (DexFileReader reader : readers) {\n            List<String> classNames = reader.getClassNames();\n            for (int i = 0; i < classNames.size(); i++) {\n                String className = classNames.get(i);\n                if (classes.add(className)) {\n                    items.add(new Item(i, reader, className));\n                }\n            }\n        }\n    }\n\n    @Override\n    public int getDexVersion() {\n        int max = DexConstants.DEX_035;","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java#L40-L76","documentation":"MultiDexFileReader.open(byte[]) throws IOException as a final fallback when the input's first bytes match neither the 'dex' magic nor the 'PK' zip prefix, i.e. the byte array is not a dex file and not a zip container. The library auto-detects format from the magic bytes and has no handler for anything else.","triggerScenarios":"Calling MultiDexFileReader.open(bytes) on content starting with anything other than 'dex' or 'PK' — e.g. an ELF .so library, a binary XML/ARSB file, a gzip stream, or plain text/HTML from a failed download.","commonSituations":"Downloading an APK via a URL that returned an HTML error page; passing an .odex/.vdex or native library where classes.dex was intended; passing a gzip-compressed dex that was never gunzipped.","solutions":["Check the first bytes of your input (file/x magic) to confirm it is a dex or zip.","If the content is gzip/other-compressed, decompress before calling open().","If you got HTML/JSON from a failed HTTP download, fix the download (check URL, status code) and retry.","For .odex/.vdex or native binaries, convert/deoptimize them to a real dex first."],"exampleFix":"// before\nBaseDexFileReader r = MultiDexFileReader.open(bytes);\n// after\nString magic = new String(bytes, 0, 3, StandardCharsets.ISO_8859_1);\nif (!magic.startsWith(\"dex\") && !magic.startsWith(\"PK\")) {\n    throw new IllegalArgumentException(\"expected dex or zip, got magic=\" + magic);\n}\nBaseDexFileReader r = MultiDexFileReader.open(bytes);","handlingStrategy":"validation","validationCode":"String magic = data.length >= 3 ? new String(data, 0, 3, StandardCharsets.ISO_8859_1) : \"\";\nif (!magic.startsWith(\"dex\") && !magic.startsWith(\"PK\")) {\n    throw new IllegalArgumentException(\"expected dex or zip, got magic=\" + magic);\n}","typeGuard":"static boolean isDexOrZip(byte[] d) {\n    return d != null && d.length >= 3 &&\n        (new String(d, 0, 3, StandardCharsets.ISO_8859_1).startsWith(\"dex\") ||\n         new String(d, 0, 2, StandardCharsets.ISO_8859_1).equals(\"PK\"));\n}","tryCatchPattern":"try {\n    BaseDexFileReader r = MultiDexFileReader.open(bytes);\n} catch (IOException e) {\n    LOG.error(\"unsupported format: \" + e.getMessage());\n}","preventionTips":["Sniff magic bytes before passing binary data to dex tools","Check HTTP status/content-type when downloading APKs (avoid saving HTML error pages)","Decompress gzip streams before handing bytes to the reader","Map file extensions (.odex/.vdex/.so) to the right tooling, not the dex reader"],"tags":["dex","android","input-validation","file-format"],"backgroundTag":"incompatible-source-type","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}