--- /dev/null
+
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+
+
+package org.apache.poi.hslf.exceptions;
+
+/**
+ * This exception is thrown when we try to open a PowerPoint file, and
+ * something is fundamentally broken about it.
+ *
+ * @author Nick Burch
+ */
+
+public class CorruptPowerPointFileException extends IllegalStateException
+{
+ public CorruptPowerPointFileException(String s) {
+ super(s);
+ }
+}
import java.io.ByteArrayOutputStream;
import java.util.Vector;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
/**
}
/**
- * Default method for finding child records of a given record
+ * Default method for finding child records of a container record
*/
public static Record[] findChildRecords(byte[] b, int start, int len) {
Vector children = new Vector(5);
int rleni = (int)rlen;
if(rleni < 0) { rleni = 0; }
+ // Abort if first record is of type 0000 and length FFFF,
+ // as that's a sign of a screwed up record
+ if(pos == 0 && type == 0l && rleni == 0xffff) {
+ throw new CorruptPowerPointFileException("Corrupt document - starts with record of type 0000 and length 0xFFFF");
+ }
+
//System.out.println("Found a " + type + " at pos " + pos + " (" + Integer.toHexString(pos) + "), len " + rlen);
Record r = createRecordForType(type,b,pos,8+rleni);
children.add(r);
} catch(InstantiationException ie) {
throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ie);
} catch(java.lang.reflect.InvocationTargetException ite) {
- throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ite);
+ throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ite + "\nCause was : " + ite.getCause());
} catch(IllegalAccessException iae) {
throw new RuntimeException("Couldn't access the constructor for type with id " + type + " on class " + c + " : " + iae);
} catch(NoSuchMethodException nsme) {
import org.apache.poi.hslf.record.SlideListWithText.*;
import org.apache.poi.hslf.record.PersistPtrHolder;
import org.apache.poi.hslf.record.PositionDependentRecord;
+import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
/**
* This class is a friendly wrapper on top of the more scary HSLFSlideShow.
// Ensure we really found a Document record
// If we didn't, then the file is probably corrupt
if(documentRecord == null) {
- throw new IllegalStateException("The PowerPoint file didn't contain a Document Record in its PersistPtr blocks. It is probably corrupt.");
+ throw new CorruptPowerPointFileException("The PowerPoint file didn't contain a Document Record in its PersistPtr blocks. It is probably corrupt.");
}