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
This commit is contained in:
Yegor Kozlov 2007-05-25 13:03:26 +00:00
parent 3bcdf011d1
commit 09b709f426
3 changed files with 29 additions and 23 deletions

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
/** /**
* This class represents the data of a link in the document. * This class represents the data of a link in the document.
@ -93,35 +94,23 @@ public class ExHyperlink extends RecordContainer {
* methods. * methods.
*/ */
private void findInterestingChildren() { 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 // First child should be the ExHyperlinkAtom
if(_children[0] instanceof ExHyperlinkAtom) { if(_children[0] instanceof ExHyperlinkAtom) {
linkAtom = (ExHyperlinkAtom)_children[0]; linkAtom = (ExHyperlinkAtom)_children[0];
} else { } else {
throw new IllegalStateException("First child record wasn't a ExHyperlinkAtom, was of type " + _children[0].getRecordType()); logger.log(POILogger.ERROR, "First child record wasn't a ExHyperlinkAtom, was of type " + _children[0].getRecordType());
} }
// Second child should be the first link details for (int i = 1; i < _children.length; i++) {
if(_children[1] instanceof CString) { if (_children[i] instanceof CString){
linkDetailsA = (CString)_children[1]; if ( linkDetailsA == null) linkDetailsA = (CString)_children[i];
} else { else linkDetailsB = (CString)_children[i];
throw new IllegalStateException("Second child record wasn't a CString, was of type " + _children[1].getRecordType()); } else {
} logger.log(POILogger.ERROR, "Record after ExHyperlinkAtom wasn't a CString, was of type " + _children[1].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
}
} }
/** /**

View File

@ -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);
}
} }