From: Yegor Kozlov Date: Fri, 25 May 2007 13:03:26 +0000 (+0000) Subject: fixed bug 42486: Failure parsing a seemingly valid PPT. Some of the assertions in... X-Git-Tag: REL_3_0_1_RC1~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=98d43d24f8d554e55894f3cc2090cade68af3b29;p=poi.git fixed bug 42486: Failure parsing a seemingly valid PPT. Some of the assertions in ExHyperlink were too strong. Write to log instead of throwing exception git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@541632 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java index dd27e5bf44..8ccc28fb9d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java @@ -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 index 0000000000..af45163c5f Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/42486.ppt differ diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java index 8a5a16c59f..4e7f2ddaa2 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java @@ -184,4 +184,21 @@ public class TestBugs extends TestCase { } } + /** + * Bug 42486: Failure parsing a seemingly valid PPT + */ + public void test42486 () throws Exception { + FileInputStream is = new FileInputStream(new File(cwd, "42486.ppt")); + HSLFSlideShow hslf = new HSLFSlideShow(is); + is.close(); + + SlideShow ppt = new SlideShow(hslf); + Slide[] slide = ppt.getSlides(); + for (int i = 0; i < slide.length; i++) { + Shape[] shape = slide[i].getShapes(); + } + assertTrue("No Exceptions while reading file", true); + + } + }