]> source.dussan.org Git - poi.git/commitdiff
fix: too many PAPX were dropped due to too strict boundary checks
authorSergey Vladimirov <sergey@apache.org>
Thu, 7 Jul 2011 09:16:26 +0000 (09:16 +0000)
committerSergey Vladimirov <sergey@apache.org>
Thu, 7 Jul 2011 09:16:26 +0000 (09:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1143720 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java
src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java

index 3923a1b3a5d1f51591e08c71fa4257da9055087f..9d0226e7599041eb123cd835d4b14a80b404873e 100644 (file)
@@ -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);
       }
     }
index 59720f1ddec53eeccc5ef95e18fb46a75309efd0..b4b02b5024395b493abd89c83df8b666488db973 100644 (file)
@@ -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<TextPiece> {
         public int compare(TextPiece textPiece, TextPiece textPiece1) {
             if (textPiece.getPieceDescriptor().fc>textPiece1.getPieceDescriptor().fc) {