{"record":{"id":"83854c1efe7ce02a","repo":"pxb1988/dex2jar","slug":"end-of-central-directory-signature-not-found","errorCode":null,"errorMessage":"End Of Central Directory signature not found","messagePattern":"End Of Central Directory signature not found","errorType":"exception","errorClass":"ZipException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/util/zip/ZipFile.java","lineNumber":216,"sourceCode":"        // final int headerMagic = raf.getInt();\n        // if (headerMagic != LOCSIG) {\n        // throw new ZipException(\"Not a zip archive\");\n        // }\n\n        long stopOffset = scanOffset - 65536;\n        if (stopOffset < 0) {\n            stopOffset = 0;\n        }\n\n        while (true) {\n            raf.position((int) scanOffset);\n            if (raf.getInt() == ENDSIG) {\n                break;\n            }\n\n            scanOffset--;\n            if (scanOffset < stopOffset) {\n                throw new ZipException(\"End Of Central Directory signature not found\");\n            }\n        }\n\n        // Read the End Of Central Directory. ENDHDR includes the signature bytes,\n        // which we've already read.\n\n        // Pull out the information we need.\n        int diskNumber = raf.getShort() & 0xffff;\n        int diskWithCentralDir = raf.getShort() & 0xffff;\n        int numEntries = raf.getShort() & 0xffff;\n        int totalNumEntries = raf.getShort() & 0xffff;\n        skip(raf, 4); // Ignore centralDirSize.\n        long centralDirOffset = ((long) raf.getInt()) & 0xffffffffL;\n        int commentLength = raf.getShort() & 0xffff;\n\n        if (numEntries != totalNumEntries || diskNumber != 0 || diskWithCentralDir != 0) {\n            throw new ZipException(\"Spanned archives not supported\");\n        }","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/util/zip/ZipFile.java#L198-L234","documentation":"ZipFile.readCentralDir scans backwards from the end of the file looking for the End Of Central Directory signature (0x06054b50). If it is not found before reaching the start of the plausible scan area, the file is not a valid (non-truncated) zip and ZipException is thrown.","triggerScenarios":"Opening files that are not zip archives, zips with corrupted/truncated EOCD, or self-extracting/odd formats where the EOCD is beyond the search stop offset.","commonSituations":"Pointing dex tooling at an APK that is actually a plain file, corrupted downloads, prepended data (e.g. self-extracting stubs) breaking EOCD search assumptions.","solutions":["Verify the input is a real zip (magic PK) before opening","Re-download/rebuild the archive","Strip leading prepended data or repair the EOCD if appending was the cause"],"exampleFix":"// before\nZipFile zip = new ZipFile(new RandomAccessFile(path, \"r\"));\n// after\nbyte[] head = new byte[4];\ntry (FileInputStream in = new FileInputStream(path)) { in.read(head); }\nif (head[0] != 'P' || head[1] != 'K') throw new IOException(\"not a zip file: \" + path);\nZipFile zip = new ZipFile(new RandomAccessFile(path, \"r\"));","handlingStrategy":"try-catch","validationCode":"byte[] tail = readLastBytes(path, 22);\nboolean hasEocd = tail[tail.length-22] == 0x50 && tail[tail.length-21] == 0x4B && tail[tail.length-20] == 0x05 && tail[tail.length-19] == 0x06;","typeGuard":"boolean hasEocdSignature(byte[] tail) { return tail.length >= 4 && tail[tail.length-22] == 'P' && tail[tail.length-21] == 'K' && tail[tail.length-20] == 5 && tail[tail.length-19] == 6; }","tryCatchPattern":"try { ZipFile z = new ZipFile(f); } catch (ZipException e) { if (e.getMessage().contains(\"End Of Central Directory\")) throw new IOException(\"corrupt or non-zip file\"); throw e; }","preventionTips":["Verify the EOCD signature near the end of the file before opening","Avoid appending/prepending bytes to zips (breaks EOCD position assumptions)","Re-download archives with checksum verification"],"tags":["zip","corrupt-file","eocd"],"backgroundTag":"invalid-argument-format","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"}