Skip to content

Commit 1b6ca36

Browse files
committed
fix chm parser
1 parent aff9175 commit 1b6ca36

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tika-parsers/src/main/java/org/apache/tika/parser/chm/accessor/ChmDirectoryListingSet.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
import java.math.BigInteger;
2222
import java.util.ArrayList;
23+
import java.util.HashSet;
2324
import java.util.List;
25+
import java.util.Set;
2426

2527
import org.apache.tika.exception.TikaException;
2628
import org.apache.tika.parser.chm.core.ChmCommons;
@@ -137,6 +139,7 @@ private void enumerateChmDirectoryListingList(ChmItsfHeader chmItsHeader,
137139

138140
/* loops over all pmgls */
139141
byte[] dir_chunk = null;
142+
Set<Integer> processed = new HashSet<>();
140143
for (int i = startPmgl; i>=0; ) {
141144
dir_chunk = new byte[(int) chmItspHeader.getBlock_len()];
142145
int start = i * (int) chmItspHeader.getBlock_len() + dir_offset;
@@ -147,10 +150,15 @@ private void enumerateChmDirectoryListingList(ChmItsfHeader chmItsHeader,
147150
PMGLheader = new ChmPmglHeader();
148151
PMGLheader.parse(dir_chunk, PMGLheader);
149152
enumerateOneSegment(dir_chunk);
150-
151-
i=PMGLheader.getBlockNext();
153+
int nextBlock = PMGLheader.getBlockNext();
154+
processed.add(i);
155+
if (processed.contains(nextBlock)) {
156+
throw new ChmParsingException("already processed block; avoiding cycle");
157+
}
158+
i=nextBlock;
152159
dir_chunk = null;
153160
}
161+
System.out.println("done");
154162
} catch (ChmParsingException e) {
155163
LOG.warn("Chm parse exception", e);
156164
} finally {

0 commit comments

Comments
 (0)