<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta6" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="add">41711 - Base class for "old version" exceptions, and new HSLF detection + use of old versions exception</action>
<action dev="POI-DEVELOPERS" type="fix">47179 - Fix string encoding issues with HSMF chunks on non-windows platforms</action>
<action dev="POI-DEVELOPERS" type="add">47183 - Attachment support for HSMF</action>
<action dev="POI-DEVELOPERS" type="fix">47154 - Handle the cell format @ as the same as General</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta6" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="add">41711 - Base class for "old version" exceptions, and new HSLF detection + use of old versions exception</action>
<action dev="POI-DEVELOPERS" type="fix">47179 - Fix string encoding issues with HSMF chunks on non-windows platforms</action>
<action dev="POI-DEVELOPERS" type="add">47183 - Attachment support for HSMF</action>
<action dev="POI-DEVELOPERS" type="fix">47154 - Handle the cell format @ as the same as General</action>
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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;
+
+/**
+ * Base class of all the exceptions that POI throws in the event
+ * that it's given a file that's older than currently supported.
+ */
+public abstract class OldFileFormatException extends IllegalArgumentException {
+ public OldFileFormatException(String s) {
+ super(s);
+ }
+}
\ No newline at end of file
==================================================================== */
package org.apache.poi.hssf;
-public class OldExcelFormatException extends IllegalArgumentException {
+import org.apache.poi.OldFileFormatException;
+
+public class OldExcelFormatException extends OldFileFormatException {
public OldExcelFormatException(String s) {
super(s);
}
--- /dev/null
+
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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;
+
+import org.apache.poi.OldFileFormatException;
+
+/**
+ * This exception is thrown when we try to open a PowerPoint file, and
+ * it's too old for us.
+ */
+public class OldPowerPointFormatException extends OldFileFormatException {
+ public OldPowerPointFormatException(String s) {
+ super(s);
+ }
+}
import org.apache.poi.util.StringUtil;
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
+import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
/**
// Decide how big it is
DocumentEntry docProps =
(DocumentEntry)dir.getEntry("Current User");
+
+ // If it's clearly junk, bail out
+ if(docProps.getSize() > 131072) {
+ throw new CorruptPowerPointFileException("The Current User stream is implausably long. It's normally 28-200 bytes long, but was " + docProps.getSize() + " bytes");
+ }
+
+ // Grab the contents
_contents = new byte[docProps.getSize()];
+ InputStream in = dir.createDocumentInputStream("Current User");
+ in.read(_contents);
- // Check it's big enough - if it's not at least 28 bytes long, then
- // the record is corrupt
+ // See how long it is. If it's under 28 bytes long, we can't
+ // read it
if(_contents.length < 28) {
+ if(_contents.length >= 4) {
+ // PPT95 has 4 byte size, then data
+ int size = LittleEndian.getInt(_contents);
+ System.err.println(size);
+ if(size + 4 == _contents.length) {
+ throw new OldPowerPointFormatException("Based on the Current User stream, you seem to have supplied a PowerPoint95 file, which isn't supported");
+ }
+ }
throw new CorruptPowerPointFileException("The Current User stream must be at least 28 bytes long, but was only " + _contents.length);
}
- // Grab the contents
- InputStream in = dir.createDocumentInputStream("Current User");
- in.read(_contents);
-
// Set everything up
init();
}
File[] files = home.listFiles();\r
for (int i = 0; i < files.length; i++) {\r
if(!files[i].getName().endsWith(".ppt")) continue;\r
+ if(files[i].getName().endsWith("PPT95.ppt")) continue;\r
+ \r
try {\r
FileInputStream is = new FileInputStream(files[i]);\r
HSLFSlideShow hslf = new HSLFSlideShow(is);\r
\r
import junit.framework.TestCase;\r
import org.apache.poi.hslf.HSLFSlideShow;\r
+import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;\r
import org.apache.poi.hslf.model.*;\r
import org.apache.poi.hslf.model.Shape;\r
\r
assertEquals(1, run.length);\r
assertEquals("Fundera, planera och involvera.", run[0].getText());\r
}\r
+ \r
+ /**\r
+ * PowerPoint 95 files should throw a more helpful exception\r
+ * @throws Exception\r
+ */\r
+ public void test41711() throws Exception {\r
+ // New file is fine\r
+ FileInputStream is = new FileInputStream(new File(cwd, "SampleShow.ppt"));\r
+ SlideShow ppt = new SlideShow(is);\r
+ \r
+ // PowerPoint 95 gives an old format exception\r
+ is = new FileInputStream(new File(cwd, "PPT95.ppt"));\r
+ try {\r
+ new SlideShow(is);\r
+ fail("OldPowerPointFormatException should've been thrown");\r
+ } catch(OldPowerPointFormatException e) {\r
+ // Good\r
+ }\r
+ }\r
}\r