From: Yegor Kozlov Date: Tue, 8 Apr 2008 14:49:59 +0000 (+0000) Subject: fix bug #44770: RuntimeException: Couldn't instantiate the class for type with id... X-Git-Tag: REL_3_0_3_BETA1~37 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e77898fa7c129bef37ede0c17a8eaebfe3cc60a2;p=poi.git fix bug #44770: RuntimeException: Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@645952 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java index db0d434aee..e42b358b89 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java @@ -119,6 +119,9 @@ public class PPDrawing extends RecordAtom * Tree walking way of finding Escher Child Records */ private void findEscherChildren(DefaultEscherRecordFactory erf, byte[] source, int startPos, int lenToGo, Vector found) { + + int escherBytes = LittleEndian.getInt( source, startPos + 4 ) + 8; + // Find the record EscherRecord r = erf.createRecord(source,startPos); // Fill it in @@ -131,6 +134,17 @@ public class PPDrawing extends RecordAtom if(size < 8) { logger.log(POILogger.WARN, "Hit short DDF record at " + startPos + " - " + size); } + + /** + * Sanity check. Always advance the cursor by the correct value. + * + * getRecordSize() must return exatcly the same number of bytes that was written in fillFields. + * Sometimes it is not so, see an example in bug #44770. Most likely reason is that one of ddf records calculates wrong size. + */ + if(size != escherBytes){ + logger.log(POILogger.WARN, "Record length=" + escherBytes + " but getRecordSize() returned " + r.getRecordSize() + "; record: " + r.getClass()); + size = escherBytes; + } startPos += size; lenToGo -= size; if(lenToGo >= 8) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java index 79d08ea65e..1aface94cd 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java @@ -185,13 +185,13 @@ public abstract class Record // Instantiate toReturn = (Record)(con.newInstance(new Object[] { b, new Integer(start), new Integer(len) })); } catch(InstantiationException ie) { - throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ie); + throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ie, ie); } catch(java.lang.reflect.InvocationTargetException ite) { - throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ite + "\nCause was : " + ite.getCause()); + throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ite + "\nCause was : " + ite.getCause(), ite); } catch(IllegalAccessException iae) { - throw new RuntimeException("Couldn't access the constructor for type with id " + type + " on class " + c + " : " + iae); + throw new RuntimeException("Couldn't access the constructor for type with id " + type + " on class " + c + " : " + iae, iae); } catch(NoSuchMethodException nsme) { - throw new RuntimeException("Couldn't access the constructor for type with id " + type + " on class " + c + " : " + nsme); + throw new RuntimeException("Couldn't access the constructor for type with id " + type + " on class " + c + " : " + nsme, nsme); } // Handling for special kinds of records follow diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/44770.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/44770.ppt new file mode 100755 index 0000000000..d7ae12b569 Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/44770.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 f3f5f8e7ee..36e45501ec 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java @@ -350,4 +350,14 @@ public class TestBugs extends TestCase { assertEquals(Picture.JPEG, pict.getType()); } + /** + * Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing + */ + public void test44770() throws Exception { + FileInputStream is = new FileInputStream(new File(cwd, "44770.ppt")); + SlideShow ppt = new SlideShow(is); + is.close(); + + assertTrue("No Exceptions while reading file", true); + } }