From 68e34318474062b908c091d1860d8cc3f911c857 Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Thu, 7 Jul 2011 09:16:26 +0000 Subject: [PATCH] fix: too many PAPX were dropped due to too strict boundary checks git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1143720 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hwpf/model/PAPBinTable.java | 2 +- .../apache/poi/hwpf/model/TextPieceTable.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java index 3923a1b3a5..9d0226e759 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java @@ -70,7 +70,7 @@ public class PAPBinTable PAPX papx = pfkp.getPAPX(y); //we don't need PAPX if they are references nowhere - if (tpt.isIndexInTable( papx.getStartBytes() )) + if (tpt.isIndexInTable( papx.getStartBytes(), papx.getEndBytes() )) _paragraphs.add(papx); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java index 59720f1dde..b4b02b5024 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java @@ -292,6 +292,27 @@ public class TextPieceTable implements CharIndexTranslator { return false; } + boolean isIndexInTable( int startBytePos, int endBytePos ) + { + for(TextPiece tp : _textPiecesFCOrder) { + int pieceStart = tp.getPieceDescriptor().getFilePosition(); + + if (startBytePos > pieceStart + tp.bytesLength()) { + continue; + } + + int left = Math.max( startBytePos, pieceStart ); + int right = Math.min( endBytePos, pieceStart + tp.bytesLength() ); + + if (left >= right) + return false; + + return true; + } + + return false; + } + private static class FCComparator implements Comparator { public int compare(TextPiece textPiece, TextPiece textPiece1) { if (textPiece.getPieceDescriptor().fc>textPiece1.getPieceDescriptor().fc) { -- 2.39.5