From eaf60c3114377f2ce9346c3bb26a569bec2bcdc8 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 21 Jul 2008 19:35:47 +0000 Subject: [PATCH] Fix bug #45437 - Detect encrypted word documents, and throw an EncryptedDocumentException instead of a OOM git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@678539 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 1 + src/documentation/content/xdocs/status.xml | 1 + .../poi/EncryptedDocumentException.java | 24 ++++++++++++++++++ .../EncryptedPowerPointFileException.java | 11 +++----- .../src/org/apache/poi/hwpf/HWPFDocument.java | 7 ++++- .../poi/hwpf/data/PasswordProtected.doc | Bin 0 -> 19968 bytes .../poi/hwpf/usermodel/TestProblems.java | 15 +++++++++++ 7 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/java/org/apache/poi/EncryptedDocumentException.java create mode 100644 src/scratchpad/testcases/org/apache/poi/hwpf/data/PasswordProtected.doc diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 021e946e7d..30c53bb213 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 45437 - Detect encrypted word documents, and throw an EncryptedDocumentException instead of a OOM 45404 - New class, hssf.usermodel.HSSFDataFormatter, for formatting numbers and dates in the same way that Excel does 45414 - Don't add too many UncalcedRecords to sheets with charts in them 45398 - Support detecting date formats containing "am/pm" as date times diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 0384580066..b81e839ef4 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 45437 - Detect encrypted word documents, and throw an EncryptedDocumentException instead of a OOM 45404 - New class, hssf.usermodel.HSSFDataFormatter, for formatting numbers and dates in the same way that Excel does 45414 - Don't add too many UncalcedRecords to sheets with charts in them 45398 - Support detecting date formats containing "am/pm" as date times diff --git a/src/java/org/apache/poi/EncryptedDocumentException.java b/src/java/org/apache/poi/EncryptedDocumentException.java new file mode 100644 index 0000000000..4922d1c81d --- /dev/null +++ b/src/java/org/apache/poi/EncryptedDocumentException.java @@ -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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java b/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java index 77f93a10f6..08eabd223b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java +++ b/src/scratchpad/src/org/apache/poi/hslf/exceptions/EncryptedPowerPointFileException.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java index a43357f021..c97d6a8bf0 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java @@ -28,6 +28,7 @@ import java.io.ByteArrayInputStream; 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 @@ public class HWPFDocument extends POIDocument 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()) { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/data/PasswordProtected.doc b/src/scratchpad/testcases/org/apache/poi/hwpf/data/PasswordProtected.doc new file mode 100644 index 0000000000000000000000000000000000000000..0d6c1690636e91f877a889c0a62d82fd689354c8 GIT binary patch literal 19968 zcmeI42{ct*|HrR+x~5AqWF|5XWlV^K5Z9D3bLQcaP?5$L0WJ+p0Bqe8!e@5a`O~K4b)Eu}!x86Wb50z97YJZ|F&)Ge$QEf*)L!C5b;=7Ns;coCyOm@nype!KggeLpGMZ0bww^Gdk@#rVS$>8ot1 z#jSCDFPO?R~%3eKqsL&S~HKX0focqmM1Q%O1h=uy{f%l$Tkqz3-%4xlp){STJuNn{JO@a)d2h zj&O_aEy;UndG(Hyx0pOO-bvkj;^mhANUDH8(O7+Kh9SD%MygbWm*!{#lIV5M6!Ts} zf*Vt226uz>q?U;!zm15;Q-Su|21h>#yAkKeZk8%zv8}WYVy~iz#z_{$Z^p=fBwdEx zlc@OI5T!OXm&3;x5&R;P=EJgnOdRo18Whq~gQ9YrL1bU<Vk;Ih< z&qbu+brKDBdu>aYfL_(jk$a!GeUg*TufQL=&a{7(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