]> source.dussan.org Git - poi.git/commitdiff
Avoid a rare ArrayIndexOutOfBoundsException on some word table stuff (patch from...
authorNick Burch <nick@apache.org>
Mon, 17 Dec 2007 14:19:19 +0000 (14:19 +0000)
committerNick Burch <nick@apache.org>
Mon, 17 Dec 2007 14:19:19 +0000 (14:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@604878 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java
src/scratchpad/testcases/org/apache/poi/hwpf/data/AIOOB-Tap.doc [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java

index 87547565f234b2f9c097a782836986f713fb733f..f8fc91f1232b865beaf0377e1fc62c9d14c083c6 100644 (file)
@@ -148,8 +148,10 @@ public class TableSprmUncompressor
 
         for (int x = 0; x < itcMac; x++)
         {
-          if(hasTCs) rgtc[x] = TableCellDescriptor.convertBytesToTC(grpprl,
-              offset + (1 + ( (itcMac + 1) * 2) + (x * 20)));
+          // Sometimes, the grpprl does not contain data at every offset. I have no idea why this happens.
+          if(hasTCs && offset + (1 + ( (itcMac + 1) * 2) + (x * 20)) < grpprl.length)
+            rgtc[x] = TableCellDescriptor.convertBytesToTC(grpprl,
+               offset + (1 + ( (itcMac + 1) * 2) + (x * 20)));
           else
             rgtc[x] = new TableCellDescriptor();
         }
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/data/AIOOB-Tap.doc b/src/scratchpad/testcases/org/apache/poi/hwpf/data/AIOOB-Tap.doc
new file mode 100644 (file)
index 0000000..bfd5906
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hwpf/data/AIOOB-Tap.doc differ
index 87b9754a623d4f285244141bb68b4a2ed71e7c0d..8e7f47ed96cb3e0652386b69ebf0f6bc094430a0 100644 (file)
@@ -53,8 +53,25 @@ public class TestProblems extends TestCase {
                Section s = r.getSection(x);
                for (int y = 0; y < s.numParagraphs(); y++) {
                        Paragraph paragraph = s.getParagraph(y);
-                       System.out.println(paragraph.getCharacterRun(0).text());
+                       //System.out.println(paragraph.getCharacterRun(0).text());
                }
        }
     }
+
+       /**
+        * AIOOB for TableSprmUncompressor.unCompressTAPOperation
+        */
+       public void testSprmAIOOB() throws Exception {
+       HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/AIOOB-Tap.doc"));
+       
+       Range r = doc.getRange();
+       StyleSheet styleSheet = doc.getStyleSheet();
+       for (int x = 0; x < r.numSections(); x++) {
+               Section s = r.getSection(x);
+               for (int y = 0; y < s.numParagraphs(); y++) {
+                       Paragraph paragraph = s.getParagraph(y);
+                       //System.out.println(paragraph.getCharacterRun(0).text());
+               }
+       }
+       }
 }