aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2006-01-03 11:54:38 +0000
committerNick Burch <nick@apache.org>2006-01-03 11:54:38 +0000
commit37d91a50848d55bbe4cb5260e243c26c3f9076f5 (patch)
treec071cb489efeba2ff58e618e221ae323f44ac2ab /src
parenteb55aa73c34443c3ff58ad2caff61fc2db42213d (diff)
downloadpoi-37d91a50848d55bbe4cb5260e243c26c3f9076f5.tar.gz
poi-37d91a50848d55bbe4cb5260e243c26c3f9076f5.zip
Add (and throw) an exception if the powerpoint file is corrupt in a way that some seem to be (first record is of type 0000, and length is 0xFFFF)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@365615 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java34
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/record/Record.java11
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java3
3 files changed, 45 insertions, 3 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java b/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java
new file mode 100644
index 0000000000..98f1e2c5b4
--- /dev/null
+++ b/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java
@@ -0,0 +1,34 @@
+
+/* ====================================================================
+ 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);
+ }
+}
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 b9dddf32b4..1e6778a5dc 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java
@@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.util.Vector;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
/**
@@ -83,7 +84,7 @@ public abstract class Record
}
/**
- * 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);
@@ -98,6 +99,12 @@ public abstract class Record
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);
@@ -148,7 +155,7 @@ public abstract class Record
} 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) {
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
index 817bd0ce5f..15b610ce09 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
@@ -36,6 +36,7 @@ import org.apache.poi.hslf.record.SlideListWithText;
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.
@@ -227,7 +228,7 @@ public class SlideShow
// 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.");
}