Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-169

RuntimeException on corrupted file

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: 1.4
    • Component/s: None
    • Labels:
      None

      Description

      We wrote a tool to simulate file corruption before parsing them with tika. This caused a few strange problems including:

      java.lang.RuntimeException: failed to skip file name in local file header
      	at org.apache.commons.compress.archivers.zip.ZipFile.resolveLocalFileHeaderData(ZipFile.java:817)
      	at org.apache.commons.compress.archivers.zip.ZipFile.<init>(ZipFile.java:207)
      	at org.apache.commons.compress.archivers.zip.ZipFile.<init>(ZipFile.java:181)
      	at org.apache.commons.compress.archivers.zip.ZipFile.<init>(ZipFile.java:142)
      	at org.apache.tika.parser.pkg.ZipContainerDetector.detect(ZipContainerDetector.java:69)
      	at org.apache.tika.detect.CompositeDetector.detect(CompositeDetector.java:60)
      	at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:113)
      	at org.apache.tika.Tika.parseToString(Tika.java:380)
      	at org.apache.tika.Tika.parseToString(Tika.java:414)
      	at no.finntech.tika.harderner.TikaIndexerHardenerTest.parseContent(TikaIndexerHardenerTest.java:106)
      	at no.finntech.tika.harderner.TikaIndexerHardenerTest.flipBitAndIndexContent(TikaIndexerHardenerTest.java:89)
      	at no.finntech.tika.harderner.TikaIndexerHardenerTest.originalFileIndexesProperly4(TikaIndexerHardenerTest.java:34)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
      

      This is caused by:

                  while (lenToSkip > 0) {
                      int skipped = archive.skipBytes(lenToSkip);
                      if (skipped <= 0) {
                          throw new RuntimeException("failed to skip file name in"
                                                     + " local file header");
                      }
                      lenToSkip -= skipped;
                  }
      

      Any reason this is using a RuntimeException instead of a IOException ? Changing it to a IOE would solve our problem.

      Finally, our test code is available from https://github.com/lacostej/tika-hardener
      You might want to reuse similar technique for your other decompressors. Let us know if you want help.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              lacostej Jerome Lacoste
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: