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
This commit is contained in:
parent
b57336834b
commit
730cbcd0d3
@ -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);
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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.");
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user