poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r678539 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/ scratchpad/src/org/apache/poi/hslf/exceptions/ scratchpad/src/org/apache/poi/hwpf/ scratchpad/testcases/org/apache/poi/hwpf/data/ scratchpad/testcases/org/apache...
Date Mon, 21 Jul 2008 19:35:47 GMT
Author: nick
Date: Mon Jul 21 12:35:47 2008
New Revision: 678539

URL: http://svn.apache.org/viewvc?rev=678539&view=rev
Log:
Fix bug #45437 - Detect encrypted word documents, and throw an EncryptedDocumentException
instead of a OOM

Added:
    poi/trunk/src/java/org/apache/poi/EncryptedDocumentException.java   (with props)
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/PasswordProtected.doc   (with
props)
Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=678539&r1=678538&r2=678539&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Mon Jul 21 12:35:47 2008
@@ -37,6 +37,7 @@
 
 		<!-- 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>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=678539&r1=678538&r2=678539&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Jul 21 12:35:47 2008
@@ -34,6 +34,7 @@
 	<!-- 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>

Added: poi/trunk/src/java/org/apache/poi/EncryptedDocumentException.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/EncryptedDocumentException.java?rev=678539&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/EncryptedDocumentException.java (added)
+++ poi/trunk/src/java/org/apache/poi/EncryptedDocumentException.java Mon Jul 21 12:35:47
2008
@@ -0,0 +1,24 @@
+/* ====================================================================
+   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);
+	}
+}

Propchange: poi/trunk/src/java/org/apache/poi/EncryptedDocumentException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java?rev=678539&r1=678538&r2=678539&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java
Mon Jul 21 12:35:47 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,19 +14,15 @@
    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);

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=678539&r1=678538&r2=678539&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Mon Jul 21 12:35:47
2008
@@ -28,6 +28,7 @@
 
 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;
@@ -174,9 +175,13 @@
     
     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())
     {

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/PasswordProtected.doc
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/PasswordProtected.doc?rev=678539&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/data/PasswordProtected.doc
------------------------------------------------------------------------------
    svn:mime-type = application/msword

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java?rev=678539&r1=678538&r2=678539&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java Mon
Jul 21 12:35:47 2008
@@ -22,6 +22,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.model.StyleSheet;
 
@@ -138,4 +139,18 @@
 		
 		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
+		}
+	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message