<!-- Don't forget to update status.xml too! -->
<release version="3.1.1-alpha1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45437 - Detect encrypted word documents, and throw an EncryptedDocumentException instead of a OOM</action>
<action dev="POI-DEVELOPERS" type="add">45404 - New class, hssf.usermodel.HSSFDataFormatter, for formatting numbers and dates in the same way that Excel does</action>
<action dev="POI-DEVELOPERS" type="fix">45414 - Don't add too many UncalcedRecords to sheets with charts in them</action>
<action dev="POI-DEVELOPERS" type="fix">45398 - Support detecting date formats containing "am/pm" as date times</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1.1-alpha1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">45437 - Detect encrypted word documents, and throw an EncryptedDocumentException instead of a OOM</action>
<action dev="POI-DEVELOPERS" type="add">45404 - New class, hssf.usermodel.HSSFDataFormatter, for formatting numbers and dates in the same way that Excel does</action>
<action dev="POI-DEVELOPERS" type="fix">45414 - Don't add too many UncalcedRecords to sheets with charts in them</action>
<action dev="POI-DEVELOPERS" type="fix">45398 - Support detecting date formats containing "am/pm" as date times</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;
+
+public class EncryptedDocumentException extends IllegalStateException
+{
+ public EncryptedDocumentException(String s) {
+ super(s);
+ }
+}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
-
-
package org.apache.poi.hslf.exceptions;
+import org.apache.poi.EncryptedDocumentException;
+
/**
* This exception is thrown when we try to open a PowerPoint file, and
* discover that it is encrypted
- *
- * @author Nick Burch
*/
-
-public class EncryptedPowerPointFileException extends IllegalStateException
+public class EncryptedPowerPointFileException extends EncryptedDocumentException
{
public EncryptedPowerPointFileException(String s) {
super(s);
import java.util.Iterator;
+import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.POIDocument;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
directory.createDocumentInputStream("WordDocument").read(_mainStream);
- // use the fib to determine the name of the table stream.
+ // Create our FIB, and check for the doc being encrypted
_fib = new FileInformationBlock(_mainStream);
+ if(_fib.isFEncrypted()) {
+ throw new EncryptedDocumentException("Cannot process encrypted word files!");
+ }
+ // use the fib to determine the name of the table stream.
String name = "0Table";
if (_fib.isFWhichTblStm())
{
import junit.framework.TestCase;
+import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.model.StyleSheet;
assertEquals(newLength, totalLength - deletedLength);
}
+
+ /**
+ * With an encrypted file, we should give a suitable
+ * exception, and not OOM
+ */
+ public void testEncryptedFile() throws Exception {
+ try {
+ new HWPFDocument(new FileInputStream(
+ new File(dirname, "PasswordProtected.doc")));
+ fail();
+ } catch(EncryptedDocumentException e) {
+ // Good
+ }
+ }
}