Skip to content

Commit

Permalink
fix chm parser
Browse files Browse the repository at this point in the history
  • Loading branch information
tballison committed Apr 16, 2018
1 parent aff9175 commit 1b6ca36
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

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

/* loops over all pmgls */
byte[] dir_chunk = null;
Set<Integer> processed = new HashSet<>();
for (int i = startPmgl; i>=0; ) {
dir_chunk = new byte[(int) chmItspHeader.getBlock_len()];
int start = i * (int) chmItspHeader.getBlock_len() + dir_offset;
Expand All @@ -147,10 +150,15 @@ private void enumerateChmDirectoryListingList(ChmItsfHeader chmItsHeader,
PMGLheader = new ChmPmglHeader();
PMGLheader.parse(dir_chunk, PMGLheader);
enumerateOneSegment(dir_chunk);

i=PMGLheader.getBlockNext();
int nextBlock = PMGLheader.getBlockNext();
processed.add(i);
if (processed.contains(nextBlock)) {
throw new ChmParsingException("already processed block; avoiding cycle");
}
i=nextBlock;
dir_chunk = null;
}
System.out.println("done");
} catch (ChmParsingException e) {
LOG.warn("Chm parse exception", e);
} finally {
Expand Down

0 comments on commit 1b6ca36

Please # to comment.