You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by ni...@apache.org on 2006/01/03 12:55:27 UTC

svn commit: r365615 - in /jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf: exceptions/CorruptPowerPointFileException.java record/Record.java usermodel/SlideShow.java

Author: nick
Date: Tue Jan  3 03:54:38 2006
New Revision: 365615

URL: http://svn.apache.org/viewcvs?rev=365615&view=rev
Log:
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)

Added:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java
Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Record.java
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java

Added: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java?rev=365615&view=auto
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java (added)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/CorruptPowerPointFileException.java Tue Jan  3 03:54:38 2006
@@ -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);
+	}
+}

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Record.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Record.java?rev=365615&r1=365614&r2=365615&view=diff
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Record.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/Record.java Tue Jan  3 03:54:38 2006
@@ -24,6 +24,7 @@
 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 @@
 	}
 
 	/**
-	 * 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 @@
 			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 @@
 		} 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) {

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java?rev=365615&r1=365614&r2=365615&view=diff
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java Tue Jan  3 03:54:38 2006
@@ -36,6 +36,7 @@
 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 @@
 	// 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.");
 	}
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/