Java util zip zipexception invalid entry crc

java.util.zip.ZipException: ошибка при открытии zip-файла

У меня есть файл Jar, который содержит другие вложенные Jars. Когда я вызываю новый конструктор JarFile() в этом файле, я получаю исключение, в котором говорится:

Когда я вручную распакую содержимое этого Jar файла и снова застегиваю его, он отлично работает. Также обратите внимание, что это исключение видно только в версиях WebSphere 6.1.0.7 и более поздних версиях. То же самое отлично работает с tomcat и WebLogic. Кроме того, когда я использую JarInputStream вместо JarFile, я могу читать содержимое файла Jar без каких-либо исключений. Пожалуйста, дайте мне знать, если у вас есть идеи о том, как это можно исправить. Спасибо, Sandhya

У меня была эта проблема на Mac, когда Windows и Linux работали просто отлично. Использование JarInputStream устранило проблему для меня.

Я столкнулся с той же проблемой при запуске Tomcat [catalina.properties]: org.apache.catalina.startup.TldConfig tldScanJar ПРЕДУПРЕЖДЕНИЕ: не удалось обработать JAR [jar: ../ opensaml.jar! /] Для файлов TLD, которые ZipException разрешить ZipException эту проблему добавьте opensaml. ~ .jar в папку Application lib.

Кажется, зависит от ОС. В Java 8 один из моих jar-файлов доступен для чтения из MacOS и Linux, но не для Windows 7. Размер jar-файла составляет около 80 МБ. Старые файлы jars хорошо читаются на той же Windows 7. Какие варианты отладки для этого были бы лучше?

11 ответов

Убедитесь, что ваш файл jar не поврежден. Если он поврежден или не сможет распаковать, эта ошибка будет иметь место.

Читайте также:  Вложенные if else javascript

Я столкнулся с той же проблемой. У меня был архив zip, который java.util.zip.ZipFile не смог обработать, но WinRar распаковал его просто отлично. Я нашел статью о SDN о параметрах сжатия и распаковки в Java. Я слегка модифицировал один из примеров кода для создания метода, который, наконец, мог обрабатывать архив. Trick использует ZipInputStream вместо ZipFile и в последовательном чтении zip-архива. Этот метод также способен обрабатывать пустой почтовый архив. Я считаю, что вы можете настроить метод в соответствии с вашими потребностями, поскольку все zip-классы имеют эквивалентные подклассы для архивов .jar.

public void unzipFileIntoDirectory(File archive, File destinationDir) throws Exception < final int BUFFER_SIZE = 1024; BufferedOutputStream dest = null; FileInputStream fis = new FileInputStream(archive); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry; File destFile; while ((entry = zis.getNextEntry()) != null) < destFile = FilesystemUtils.combineFileNames(destinationDir, entry.getName()); if (entry.isDirectory()) < destFile.mkdirs(); continue; >else < int count; byte data[] = new byte[BUFFER_SIZE]; destFile.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(destFile); dest = new BufferedOutputStream(fos, BUFFER_SIZE); while ((count = zis.read(data, 0, BUFFER_SIZE)) != -1) < dest.write(data, 0, count); >dest.flush(); dest.close(); fos.close(); > > zis.close(); fis.close(); > 

Он может быть связан с log4j.

У вас есть файл log4j.jar в пути класса Java Java (как определено в файле запуска), а также пути к классу приложений?

Если вы убедитесь, что файл log4j.jar находится в пути класса java и что он НЕ находится в каталоге web-inf/lib вашего веб-приложения.

Он также может быть связан с ant version (может быть, это не ваш случай, но я его здесь помещаю для справки):

У вас есть .class файл в вашем пути к классу (т.е. не каталог или файл .jar). Начиная с ant 1.6, ant откроет файлы в проверке классов для записей манифеста. Это попытка открытия завершится с ошибкой «java.util.zip.ZipException»

Проблема не существует с ant 1.5, так как она не пытается открыть файлы. — поэтому убедитесь, что ваш classpath не содержит файлы .class.

С другой стороны, считали ли вы, что отдельные банки?
Вы можете в манифесте вашей главной банки, обратитесь к другим баночкам с этим атрибутом:

Class-Path: one.jar two.jar three.jar 

Затем поместите все ваши банки в одну папку.
Опять же, может быть недействительным для вашего дела, но все еще там для справки.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: java.util.zip.ZipException: invalid entry CRC #6

Error: java.util.zip.ZipException: invalid entry CRC #6

Comments

Hi, I manually installed the filters as per [1] in an empty git repository. Then I created a simple .odt file with just a single line. git commit the file, added a simple mod and tried to see the diff. Here is the error I got:

$ git diff warning: CRLF will be replaced by LF in hello.odt. The file will have its original line endings in your working directory Exception in thread "main" java.util.zip.ZipException: invalid entry CRC (expected 0xecf40a9d but got 0x716ecc7d) at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:224) at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107) at io.github.hoijui.rezipdoc.Utils.transferTo(Utils.java:348) at io.github.hoijui.rezipdoc.ReZip.reZip(ReZip.java:248) at io.github.hoijui.rezipdoc.ReZip.reZip(ReZip.java:229) at io.github.hoijui.rezipdoc.ReZip.reZip(ReZip.java:201) at io.github.hoijui.rezipdoc.ReZip.main(ReZip.java:188) error: external filter 'java -cp .git/rezipdoc-*.jar io.github.hoijui.rezipdoc.ReZip --compressed' failed 1 error: external filter 'java -cp .git/rezipdoc-*.jar io.github.hoijui.rezipdoc.ReZip --compressed' failed Exception in thread "main" java.util.zip.ZipException: invalid entry CRC (expected 0xecf40a9d but got 0x716ecc7d) at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:224) at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107) at io.github.hoijui.rezipdoc.Utils.transferTo(Utils.java:348) at io.github.hoijui.rezipdoc.ZipDoc.transform(ZipDoc.java:153) at io.github.hoijui.rezipdoc.ZipDoc.transform(ZipDoc.java:125) at io.github.hoijui.rezipdoc.ZipDoc.main(ZipDoc.java:112) fatal: unable to read files to diff
$ java --version openjdk 11.0.11 2021-04-20 OpenJDK Runtime Environment (build 11.0.11+9-post-Debian-1) OpenJDK 64-Bit Server VM (build 11.0.11+9-post-Debian-1, mixed mode, sharing)
$ uname -a Linux [. ] 5.10.0-6-amd64 #1 SMP Debian 5.10.28-1 (2021-04-09) x86_64 GNU/Linux $ lsb_release -a Distributor ID: Debian Description: Debian GNU/Linux 11 (bullseye) Release: 11 Codename: bullseye 

The text was updated successfully, but these errors were encountered:

thank you for the report, and sorry for the late answer!
So it looks like the Java internal ZIP library found an error in that ODT file. I would argue, that this either means, the file is not in the ZIP format, or it is corrupted. It seems very unlikely to me, that the Java internal ZIP implementation is buggy.
I just checked on my system, and my ODT files seem to be valid ZIP files. Can you check yours with:

Hi @hoijui, thanks for replying! So, I re-did all the steps I reported and was able to reproduce the behaviour again. As requested see below, I don’t think the file corrupted or anything.

$ git status On branch master Changes not staged for commit: (use "git add . " to update what will be committed) (use "git restore . " to discard changes in working directory) modified: hello.odt no changes added to commit (use "git add" and/or "git commit -a") $ git diff warning: CRLF will be replaced by LF in hello.odt. The file will have its original line endings in your working directory Exception in thread "main" java.util.zip.ZipException: invalid entry CRC (expected 0x1832bedd but got 0xfe27eff6) at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:224) at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107) at io.github.hoijui.rezipdoc.Utils.transferTo(Utils.java:348) at io.github.hoijui.rezipdoc.ReZip.reZip(ReZip.java:248) at io.github.hoijui.rezipdoc.ReZip.reZip(ReZip.java:229) at io.github.hoijui.rezipdoc.ReZip.reZip(ReZip.java:201) at io.github.hoijui.rezipdoc.ReZip.main(ReZip.java:188) error: external filter 'java -cp .git/rezipdoc-*.jar io.github.hoijui.rezipdoc.ReZip --compressed' failed 1 error: external filter 'java -cp .git/rezipdoc-*.jar io.github.hoijui.rezipdoc.ReZip --compressed' failed Exception in thread "main" java.util.zip.ZipException: invalid entry CRC (expected 0x1832bedd but got 0xfe27eff6) at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:224) at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107) at io.github.hoijui.rezipdoc.Utils.transferTo(Utils.java:348) at io.github.hoijui.rezipdoc.ZipDoc.transform(ZipDoc.java:153) at io.github.hoijui.rezipdoc.ZipDoc.transform(ZipDoc.java:125) at io.github.hoijui.rezipdoc.ZipDoc.main(ZipDoc.java:112) fatal: unable to read files to diff $ unzip -t hello.odt Archive: hello.odt testing: mimetype OK testing: Configurations2/toolbar/ OK testing: Configurations2/floater/ OK testing: Configurations2/popupmenu/ OK testing: Configurations2/menubar/ OK testing: Configurations2/accelerator/ OK testing: Configurations2/toolpanel/ OK testing: Configurations2/progressbar/ OK testing: Configurations2/statusbar/ OK testing: Configurations2/images/Bitmaps/ OK testing: manifest.rdf OK testing: meta.xml OK testing: settings.xml OK testing: Thumbnails/thumbnail.png OK testing: styles.xml OK testing: content.xml OK testing: META-INF/manifest.xml OK No errors detected in compressed data of hello.odt. 

I tried with a FreeCAD file to confirm the installation was correct and it works OK (had to add «*.FCStd reZipDoc» at the end of file .git/info/attributes )

$ git status On branch master Changes not staged for commit: (use "git add . " to update what will be committed) (use "git restore . " to discard changes in working directory) modified: cube.FCStd no changes added to commit (use "git add" and/or "git commit -a") $ git diff diff --git a/cube.FCStd b/cube.FCStd index ab6c899..ff5f8bf 100644 --- a/cube.FCStd +++ b/cube.FCStd @@ -30,7 +30,7 @@ Sub-file: Document.xml  - +   [. ] 

I’ve tried with an ‘.ods’ file just in case it was only a problem with Writer and I got the same error (see third chunk of code).

$ git status On branch master Changes not staged for commit: (use "git add . " to update what will be committed) (use "git restore . " to discard changes in working directory) modified: hello.ods no changes added to commit (use "git add" and/or "git commit -a") $ git diff warning: CRLF will be replaced by LF in hello.ods. The file will have its original line endings in your working directory Exception in thread "main" java.util.zip.ZipException: invalid entry CRC (expected 0xd15794a2 but got 0x1bf12e26) at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:224) at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107) at io.github.hoijui.rezipdoc.Utils.transferTo(Utils.java:348) at io.github.hoijui.rezipdoc.ReZip.reZip(ReZip.java:248) at io.github.hoijui.rezipdoc.ReZip.reZip(ReZip.java:229) at io.github.hoijui.rezipdoc.ReZip.reZip(ReZip.java:201) at io.github.hoijui.rezipdoc.ReZip.main(ReZip.java:188) error: external filter 'java -cp .git/rezipdoc-*.jar io.github.hoijui.rezipdoc.ReZip --compressed' failed 1 error: external filter 'java -cp .git/rezipdoc-*.jar io.github.hoijui.rezipdoc.ReZip --compressed' failed Exception in thread "main" java.util.zip.ZipException: invalid entry CRC (expected 0xd15794a2 but got 0x1bf12e26) at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:224) at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107) at io.github.hoijui.rezipdoc.Utils.transferTo(Utils.java:348) at io.github.hoijui.rezipdoc.ZipDoc.transform(ZipDoc.java:153) at io.github.hoijui.rezipdoc.ZipDoc.transform(ZipDoc.java:125) at io.github.hoijui.rezipdoc.ZipDoc.main(ZipDoc.java:112) fatal: unable to read files to diff 

Anything else I can do to debug this further please let me know. Disclaimer: my knowledge of Java is very limited :P.

Источник

Оцените статью