You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Peter Alfred Lee (Jira)" <ji...@apache.org> on 2020/03/04 04:01:00 UTC

[jira] [Commented] (COMPRESS-506) ZipException when on ZipArchiveInputStream but not ZipFile

    [ https://issues.apache.org/jira/browse/COMPRESS-506?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17050755#comment-17050755 ] 

Peter Alfred Lee commented on COMPRESS-506:
-------------------------------------------

I tested with the attached zip and found that it's the problem of the *mimetype*.

I'm not sure if you are familiar with zip specification([https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT]). I'm pretending that you're familiar with it.  :)

 

The *general purpose bit flag* in the *Local File Header* of *mimetype* indicates that it has no *Data Descriptor*, which actually has one. So we didn't skip the *Data Descriptor of mimetype*. When reading the *P0/content.xml*, we are actually reading the *Data Descriptor of mimetype* as we didn't skip it beforehand, which caused an exception.

 

We can have a wordaround here : just skip the data descriptor when the signature of Data Descriptor was met. But I believe it's not the best practice.

 

Would you please tell me how is the zip file created?

And I think the *ZipFile* would work here instead of ZipArchiveInputStream, as it's reading from the Central File Header instead of Local File Head.

> ZipException when on ZipArchiveInputStream but not ZipFile
> ----------------------------------------------------------
>
>                 Key: COMPRESS-506
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-506
>             Project: Commons Compress
>          Issue Type: Task
>            Reporter: Tim Allison
>            Priority: Major
>         Attachments: ooo-5948.bau.zip
>
>
> Over on Apache Tika, we recently gathered files from a number of bug trackers.
>  We found that this file (https://bz.apache.org/ooo/attachment.cgi?id=17659) causes an exception with ZipArchiveInputStream but not with ZipFile.  Java's ZipInputStream silently stops after the second entry.  Not sure if it matters, but note that the first entry has zero bytes.
> linux commandline {{unzip}} is able to unzip the file without problems.
> To replicate the problem:
> {noformat}
>     @Test
>     public void testOneOff() throws Exception {
>         Path p = Paths.get(".../ooo-5948.bau");
>         try(ZipFile zip = new ZipFile(p.toFile())) {
>             Enumeration<ZipArchiveEntry> enm = zip.getEntries();
>             while (enm.hasMoreElements()) {
>                 ZipArchiveEntry zae = enm.nextElement();
>                 System.out.println("commons-compress zipFile: "+zae.getName());
>             }
>         }
>         try (InputStream is = Files.newInputStream(p)) {
>             try (ZipArchiveInputStream zais = new ZipArchiveInputStream(is)) {
>                 ZipArchiveEntry zae = zais.getNextZipEntry();
>                 while (zae != null) {
>                     System.out.println("commons-compress stream: " + zae.getName());
>                     zae = zais.getNextZipEntry();
>                 }
>             }
>         } catch (ZipException e) {
>             e.printStackTrace();
>         }
>         try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(p))) {
>             ZipEntry ze = zipInputStream.getNextEntry();
>             while (ze != null) {
>                 System.out.println("java zip stream: " + ze.getName());
>                 ze = zipInputStream.getNextEntry();
>             }
>         }
>     }
> {noformat}
> output:
> {noformat}
> commons-compress zipFile: mimetype
> commons-compress zipFile: P0/content.xml
> commons-compress zipFile: P0/styles.xml
> commons-compress zipFile: P1/content.xml
> commons-compress zipFile: P1/styles.xml
> commons-compress zipFile: P2/content.xml
> commons-compress zipFile: P2/styles.xml
> commons-compress zipFile: P3/content.xml
> commons-compress zipFile: P3/styles.xml
> commons-compress zipFile: P4/content.xml
> commons-compress zipFile: P4/styles.xml
> commons-compress zipFile: P5/content.xml
> commons-compress zipFile: P5/styles.xml
> commons-compress zipFile: P6/content.xml
> commons-compress zipFile: P6/styles.xml
> commons-compress zipFile: P7/content.xml
> commons-compress zipFile: P7/styles.xml
> commons-compress zipFile: P8/content.xml
> commons-compress zipFile: P8/styles.xml
> commons-compress zipFile: P9/content.xml
> commons-compress zipFile: P9/styles.xml
> commons-compress zipFile: PF/content.xml
> commons-compress zipFile: PF/styles.xml
> commons-compress zipFile: BlockList.xml
> commons-compress zipFile: META-INF/manifest.xml
> commons-compress stream: mimetype
> commons-compress stream: P0/content.xml
> java.util.zip.ZipException: Unexpected record signature: 0X8074B50
> 	at org.apache.commons.compress.archivers.zip.ZipArchiveInputStream.getNextZipEntry(ZipArchiveInputStream.java:286)
> 	at org.apache.tika.detect.TestContainerAwareDetector.testOneOff(TestContainerAwareDetector.java:245)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:498)
> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
> 	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> 	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
> 	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
> 	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
> 	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
> 	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
> 	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
> 	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
> 	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
> 	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
> 	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
> 	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
> 	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
> java zip stream: mimetype
> java zip stream: P0/content.xml
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)