{"record":{"id":"6f532b27dde40e31","repo":"pxb1988/dex2jar","slug":"file-too-small-to-be-a-dex-zip","errorCode":null,"errorMessage":"File too small to be a dex/zip","messagePattern":"File too small to be a dex/zip","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java","lineNumber":34,"sourceCode":"    final private List<Item> items = new ArrayList<>();\n\n    public MultiDexFileReader(Collection<DexFileReader> readers) {\n        this.readers.addAll(readers);\n        init();\n    }\n\n    private static byte[] toByteArray(InputStream is) throws IOException {\n        AccessBufByteArrayOutputStream out = new AccessBufByteArrayOutputStream();\n        byte[] buff = new byte[1024];\n        for (int c = is.read(buff); c > 0; c = is.read(buff)) {\n            out.write(buff, 0, c);\n        }\n        return out.getBuf();\n    }\n\n    public static BaseDexFileReader open(byte[] data) throws IOException {\n        if (data.length < 3) {\n            throw new IOException(\"File too small to be a dex/zip\");\n        }\n        if (\"dex\".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex\n            return new DexFileReader(data);\n        } else if (\"PK\".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP\n            TreeMap<String, DexFileReader> dexFileReaders = new TreeMap<>();\n            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) {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java#L16-L52","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nBaseDexFileReader r = MultiDexFileReader.open(data);\n// after\nif (data == null || data.length < 3) {\n    throw new IllegalArgumentException(\"input too small to be dex/zip: \" + (data == null ? -1 : data.length));\n}\nBaseDexFileReader r = MultiDexFileReader.open(data);","handlingStrategy":"validation","validationCode":"if (data == null || data.length < 3) {\n    throw new IllegalArgumentException(\"input bytes too small to be a dex/zip: \" + (data == null ? \"null\" : data.length));\n}","typeGuard":null,"tryCatchPattern":"try {\n    BaseDexFileReader r = MultiDexFileReader.open(data);\n} catch (IOException e) {\n    LOG.error(\"input is not a dex/zip: \" + e.getMessage());\n}","preventionTips":["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"],"tags":["dex","android","input-validation","zip"],"backgroundTag":"invalid-argument-value","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"}