{"record":{"id":"b24cc989fc1c4f1a","repo":"skylot/jadx","slug":"failed-to-open-zip-error","errorCode":null,"errorMessage":"Failed to open zip: {}, error: {}","messagePattern":"Failed to open zip: (.+?), error: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"jadx-commons/jadx-zip/src/main/java/jadx/zip/parser/JadxZipParser.java","lineNumber":86,"sourceCode":"\n\t@Override\n\tpublic ZipContent open() throws IOException {\n\t\tload();\n\t\ttry {\n\t\t\tint maxEntriesCount = zipSecurity.getMaxEntriesCount();\n\t\t\tif (maxEntriesCount == -1) {\n\t\t\t\tmaxEntriesCount = Integer.MAX_VALUE;\n\t\t\t}\n\t\t\tList<IZipEntry> entries;\n\t\t\tif (flags.contains(ZipReaderFlags.IGNORE_CENTRAL_DIR_ENTRIES)) {\n\t\t\t\tentries = searchLocalFileHeaders(maxEntriesCount);\n\t\t\t} else {\n\t\t\t\tentries = loadFromCentralDirs(maxEntriesCount);\n\t\t\t}\n\t\t\treturn new ZipContent(this, entries);\n\t\t} catch (Exception e) {\n\t\t\tif (flags.contains(ZipReaderFlags.DONT_USE_FALLBACK)) {\n\t\t\t\tthrow new IOException(\"Failed to open zip: \" + zipFile + \", error: \" + e.getMessage(), e);\n\t\t\t}\n\t\t\tLOG.warn(\"Zip open failed, switching to fallback parser, zip: {}\", zipFile, e);\n\t\t\treturn initFallbackParser();\n\t\t}\n\t}\n\n\tpublic boolean canOpen() {\n\t\ttry {\n\t\t\tload();\n\t\t\tint eocdStart = searchEndOfCDStart();\n\t\t\tByteBuffer buf = getBuffer();\n\t\t\tbuf.position(eocdStart + 4);\n\t\t\tint diskNum = readU2(buf);\n\t\t\tif (diskNum != 0xFFFF) { // Zip64 not supported\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\tLOG.warn(\"Jadx parser can't open zip file: {}\", zipFile, e);","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/skylot/jadx/blob/e738a26571d02919f01df40de93bc9a44dee4e18/jadx-commons/jadx-zip/src/main/java/jadx/zip/parser/JadxZipParser.java#L68-L104","documentation":"The top-level failure when the custom JadxZipParser cannot build a ZipContent and the caller has opted out of the fallback parser via ZipReaderFlags.DONT_USE_FALLBACK. Without that flag jadx would log a warning and silently switch to the fallback parser; with the flag, the original exception is wrapped into an IOException that includes the zip path and the root message. The original cause is chained.","triggerScenarios":"Opening a zip through JadxZipParser.load()/open() with a ZipReaderOptions whose flags contain DONT_USE_FALLBACK, when either loadFromCentralDirs() or searchLocalFileHeaders() throws (missing EOCD, bad central directory, IO error, max-entries exceeded).","commonSituations":"A CI job or programmatic jadx invocation that disables the fallback for reproducibility/strictness, run against a malformed or non-zip file; an archive whose end-of-central-directory record is absent or corrupted; a file that is not actually a zip despite its extension.","solutions":["Remove ZipReaderFlags.DONT_USE_FALLBACK from the options so jadx can retry with the fallback parser (default behavior).","Inspect getCause() to find the structural reason (missing EOCD, IO error, etc.).","Confirm the file is actually a zip/APK and not truncated or zero-byte.","If strict parsing is required, pre-validate the file with a CRC/structure check before handing it to jadx."],"exampleFix":"// before\nZipReaderOptions opts = new ZipReaderOptions(security, EnumSet.of(ZipReaderFlags.DONT_USE_FALLBACK));\nZipContent content = new JadxZipParser(file, opts).open();\n\n// after\nZipReaderOptions opts = new ZipReaderOptions(security, ZipReaderFlags.none());\nZipContent content = new JadxZipParser(file, opts).open();","handlingStrategy":"validation","validationCode":"// Validate the file is a plausible zip and below parser limits before opening.\nimport java.util.zip.ZipFile;\nif (!file.isFile() || file.length() == 0) {\n    throw new IOException(\"Not a readable zip: \" + file);\n}\n// Confirm magic bytes 'PK'\ntry (RandomAccessFile raf = new RandomAccessFile(file, \"r\")) {\n    int sig = raf.readInt();\n    if ((sig & 0xFFFF) != 0x4B50) { // 'PK'\n        throw new IOException(\"Not a zip file (bad magic): \" + file);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    ZipContent content = parser.open();\n} catch (IOException e) {\n    // message: \"Failed to open zip: <file>, error: <reason>\"\n    LOG.error(\"Custom parser (no fallback) could not open zip: {}\", e.getMessage());\n    // optionally retry WITHOUT DONT_USE_FALLBACK\n}","preventionTips":["Do not set ZipReaderFlags.DONT_USE_FALLBACK unless you specifically need strict parsing.","Pre-check the file is a non-empty zip via magic bytes before invoking jadx.","For programmatic use, default to letting jadx fall back rather than hard-failing."],"tags":["zip","io","fallback-parser","corrupted-archive"],"backgroundTag":null,"analyzedSha":"e738a26571d02919f01df40de93bc9a44dee4e18","analyzedAt":"2026-08-14T00:10:24.238Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}