You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ju...@apache.org on 2013/12/27 04:46:09 UTC

svn commit: r1553621 - /tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmLzxBlock.java

Author: jukka
Date: Fri Dec 27 03:46:09 2013
New Revision: 1553621

URL: http://svn.apache.org/r1553621
Log:
TIKA-1152: Process loops infinitely on parsing of a CHM file

Patch by Hong-Thai Nguyen

Modified:
    tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmLzxBlock.java

Modified: tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmLzxBlock.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmLzxBlock.java?rev=1553621&r1=1553620&r2=1553621&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmLzxBlock.java (original)
+++ tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmLzxBlock.java Fri Dec 27 03:46:09 2013
@@ -106,7 +106,8 @@ public class ChmLzxBlock {
     private void extractContent() throws TikaException {
         assertStateNotNull();
         if (getChmSection().getData() != null) {
-            while (getContentLength() < getBlockLength()) {// && tempStopLoop
+            boolean continueLoop = true;
+            while (continueLoop && getContentLength() < getBlockLength()) {
                 if (getState() != null && getState().getBlockRemaining() == 0) {
                     if (getState().getHadStarted() == LzxState.NOT_STARTED_DECODING) {
                         getState().setHadStarted(LzxState.STARTED_DECODING);
@@ -183,6 +184,7 @@ public class ChmLzxBlock {
                     getState().setBlockRemaining(0);
                 }
 
+                int lastLength = getContentLength();
                 switch (getState().getBlockType()) {
                 case ChmCommons.ALIGNED_OFFSET:
                     // if(prevblock.lzxState.length>prevblock.lzxState.remaining)
@@ -200,6 +202,8 @@ public class ChmLzxBlock {
                 if ((getState().getFramesRead() < 32768)
                         && getState().getIntelFileSize() != 0)
                     intelE8Decoding();
+
+                continueLoop = getContentLength() > lastLength;
             }
         }
     }
@@ -277,7 +281,7 @@ public class ChmLzxBlock {
                         ChmConstants.LZX_NUM_SECONDARY_LENGTHS));
     }
 
-    public void decompressUncompressedBlock(int len, byte[] prevcontent) {
+    private void decompressUncompressedBlock(int len, byte[] prevcontent) {
         if (getContentLength() + getState().getBlockRemaining() <= getBlockLength()) {
             for (int i = getContentLength(); i < (getContentLength() + getState()
                     .getBlockRemaining()); i++)
@@ -296,7 +300,7 @@ public class ChmLzxBlock {
         }
     }
 
-    public void decompressAlignedBlock(int len, byte[] prevcontent) throws TikaException {
+    private void decompressAlignedBlock(int len, byte[] prevcontent) throws TikaException {
 
         if ((getChmSection() == null) || (getState() == null)
                 || (getState().getMainTreeTable() == null))