]> source.dussan.org Git - poi.git/commitdiff
fixed bug 42486: Failure parsing a seemingly valid PPT. Some of the assertions in...
authorYegor Kozlov <yegor@apache.org>
Fri, 25 May 2007 13:03:26 +0000 (13:03 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 25 May 2007 13:03:26 +0000 (13:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@541632 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java
src/scratchpad/testcases/org/apache/poi/hslf/data/42486.ppt [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java

index dd27e5bf44c474b15c864a2f21a7e94130e460b7..8ccc28fb9dd3cf402c99a3f8d2ba9b3745ccc64b 100644 (file)
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogger;
 
 /**
  * This class represents the data of a link in the document. 
@@ -93,37 +94,25 @@ public class ExHyperlink extends RecordContainer {
         *  methods.
         */     
        private void findInterestingChildren() {
-               // We need to have 2 children, ideally 3, and sometimes have more
-               if(_children.length < 2) {
-                       throw new IllegalStateException("We need at least two child records, but we only had " + _children.length);
-               }
 
                // First child should be the ExHyperlinkAtom
                if(_children[0] instanceof ExHyperlinkAtom) {
                        linkAtom = (ExHyperlinkAtom)_children[0];
                } else {
-                       throw new IllegalStateException("First child record wasn't a ExHyperlinkAtom, was of type " + _children[0].getRecordType());
-               }
-               
-               // Second child should be the first link details
-               if(_children[1] instanceof CString) {
-                       linkDetailsA = (CString)_children[1];
-               } else {
-                       throw new IllegalStateException("Second child record wasn't a CString, was of type " + _children[1].getRecordType());
+                       logger.log(POILogger.ERROR, "First child record wasn't a ExHyperlinkAtom, was of type " + _children[0].getRecordType());
                }
 
-               // Third child, if it exists, should be the second link details
-               if(_children.length >= 3) {
-                       if(_children[2] instanceof CString) {
-                               linkDetailsB = (CString)_children[2];
-                       } else {
-                               throw new IllegalStateException("Third child record wasn't a CString, was of type " + _children[2].getRecordType());
-                       }
-               } else {
-                       // Should be fine to not have one
-               }
+        for (int i = 1; i < _children.length; i++) {
+            if (_children[i] instanceof CString){
+                if ( linkDetailsA == null) linkDetailsA = (CString)_children[i];
+                else linkDetailsB = (CString)_children[i];
+            } else {
+                logger.log(POILogger.ERROR, "Record after ExHyperlinkAtom wasn't a CString, was of type " + _children[1].getRecordType());
+            }
+
+        }
        }
-       
+
        /**
         * Create a new ExHyperlink, with blank fields
         */
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/42486.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/42486.ppt
new file mode 100644 (file)
index 0000000..af45163
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/42486.ppt differ
index 8a5a16c59f1fc961b7cd8a80c4f0d49b25102585..4e7f2ddaa28ad91df4a53286024df1b8917e9b21 100644 (file)
@@ -184,4 +184,21 @@ public class TestBugs extends TestCase {
         }\r
     }\r
 \r
+    /**\r
+     * Bug 42486:  Failure parsing a seemingly valid PPT\r
+     */\r
+    public void test42486 () throws Exception {\r
+        FileInputStream is = new FileInputStream(new File(cwd, "42486.ppt"));\r
+        HSLFSlideShow hslf = new HSLFSlideShow(is);\r
+        is.close();\r
+\r
+        SlideShow ppt = new SlideShow(hslf);\r
+        Slide[] slide = ppt.getSlides();\r
+        for (int i = 0; i < slide.length; i++) {\r
+            Shape[] shape = slide[i].getShapes();\r
+        }\r
+        assertTrue("No Exceptions while reading file", true);\r
+\r
+    }\r
+\r
 }\r