From 530a209d0197b8855c9436bdce402360de1f7f2d Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Sat, 9 Jul 2011 14:47:19 +0000 Subject: [PATCH] add the same boundaries check to CHPX / PAPX / SEPX for Word95 as for Word97 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1144681 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/apache/poi/hwpf/model/OldCHPBinTable.java | 4 +++- .../src/org/apache/poi/hwpf/model/OldPAPBinTable.java | 3 ++- .../src/org/apache/poi/hwpf/model/OldSectionTable.java | 8 ++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldCHPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldCHPBinTable.java index 089207dfb..146fd3b3f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldCHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldCHPBinTable.java @@ -61,7 +61,9 @@ public final class OldCHPBinTable extends CHPBinTable for (int y = 0; y < fkpSize; y++) { - _textRuns.add(cfkp.getCHPX(y)); + CHPX chpx = cfkp.getCHPX(y); + if (chpx != null && tpt.isIndexInTable( chpx.getStartBytes(), chpx.getEndBytes() )) + _textRuns.add(chpx); } } Collections.sort( _textRuns, PropertyNode.StartComparator.instance ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldPAPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldPAPBinTable.java index b8b0fc3c2..9771e5efc 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldPAPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldPAPBinTable.java @@ -53,7 +53,8 @@ public final class OldPAPBinTable extends PAPBinTable for (int y = 0; y < fkpSize; y++) { PAPX papx = pfkp.getPAPX(y); - _paragraphs.add(papx); + if (papx != null && tpt.isIndexInTable( papx.getStartBytes(), papx.getEndBytes() )) + _paragraphs.add(papx); } } Collections.sort( _paragraphs, PropertyNode.StartComparator.instance ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java index db84825e0..2c212a6e3 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java @@ -49,10 +49,11 @@ public final class OldSectionTable extends SectionTable int startAt = node.getStart(); int endAt = node.getEnd(); + SEPX sepx; // check for the optimization if (fileOffset == 0xffffffff) { - _sections.add(new SEPX(sed, startAt, endAt, charConv, new byte[0])); + sepx = new SEPX(sed, startAt, endAt, charConv, new byte[0]); } else { @@ -65,8 +66,11 @@ public final class OldSectionTable extends SectionTable byte[] buf = new byte[sepxSize+2]; fileOffset += LittleEndian.SHORT_SIZE; System.arraycopy(documentStream, fileOffset, buf, 0, buf.length); - _sections.add(new SEPX(sed, startAt, endAt, charConv, buf)); + sepx = new SEPX(sed, startAt, endAt, charConv, buf); } + + if (tpt.isIndexInTable( sepx.getStartBytes(), sepx.getEndBytes() )) + _sections.add(sepx); } Collections.sort( _sections, PropertyNode.StartComparator.instance ); }