java.util.zip.ZipException: invalid CEN header (bad signature)
Asked Answered
P

1

9

I'm getting this error when doing this (relatively simple) piece of code:

    ZipFile zf = new ZipFile(fn);
    Enumeration<? extends ZipEntry> eze = zf.entries();
    while (eze.hasMoreElements()) {
        ZipEntry ze = eze.nextElement();
        System.out.println(ze.getName());
    }
    zf.close();

Actually. Interestingly enough, I get it on java-sun-6u32 and java-1.6.0-openjdk-amd64, but java-sun-7u4 succeeds. unzip itself seems to handle it fine. I'm guessing that means that these zipfiles are perhaps created by some newer version of zip that java 7 understands, but that previous versions do not. But, any insight would be appreciated. Also, since in production I don't really have the option of using java 7, any way of making earlier versions of java understand this new version of zip (if that in fact is what the problem is, of course.)

Thanks!

Prostate answered 10/9, 2012 at 6:58 Comment(6)
sigh, unfortunately, I can't.. The files in question are ginormous (707 megs) and I'm not producing them.Prostate
Hmm.. However: I can do 7z l -slt whatever.zip and get ` 7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18 p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,8 CPUs) Listing archive: ./081212j400-13_file1of3.zip -- Path = ./081212j400-13_file1of3.zip Type = zip 64-bit = + Physical Size = 707951519 ` Hm. I can not seem to format that properly. Hopefully it still comes across tho.Prostate
If you're on *nix, what does file your.zip say? Or you can just chop off first 512 kb or so off file and place somewhere.Ginkgo
ahh, it seems to be zip64 :) AFAIR, for java6 you will have to resort to external library (such as commons.apache.org/compress/zip.html)Ginkgo
@barti_ddu, if you make that into an answer, I'll upvote you, and declare it the right answer.. Thanks!Prostate
Not at all, your guesses where perfectly correct; good luck!Ginkgo
G
15

7z l -slt output provided in your comment is quite useful:

Type = zip 64-bit

gives a hint, that it's ZIP64 (version 4.5 of ZIP specification). However, though Java7 supports it, this support is not backported to Java6 at the moment and you will have to resort to external library such as Apache Compress.

P.S. For reference, file test.zip would output something like

test.zip: Zip archive data, at least v4.5 to extract
Ginkgo answered 10/9, 2012 at 22:9 Comment(2)
For me the file format was correct but the JAR exceeded 100MB which was tripping up some setting on our cluster. Hope this helps someone.Export
Zip tools like 7zip automatically change to 64bit when the zip size exceeds 4GB (obviously)Lallation

© 2022 - 2024 — McMap. All rights reserved.