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
This commit is contained in:
Yegor Kozlov 2008-04-08 14:49:59 +00:00
parent 3174b1bf34
commit e534579881
4 changed files with 28 additions and 4 deletions

View File

@ -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) {

View File

@ -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

Binary file not shown.

View File

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