You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ta...@apache.org on 2016/10/20 15:13:17 UTC
svn commit: r1765829 - in /poi/trunk:
src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
test-data/spreadsheet/60284.xls
Author: tallison
Date: Thu Oct 20 15:13:16 2016
New Revision: 1765829
URL: http://svn.apache.org/viewvc?rev=1765829&view=rev
Log:
BUG-60284 -- throw EncryptedDocumentException for password protected OldExcel files
Added:
poi/trunk/test-data/spreadsheet/60284.xls (with props)
Modified:
poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
Modified: poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java?rev=1765829&r1=1765828&r2=1765829&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java Thu Oct 20 15:13:16 2016
@@ -28,6 +28,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.CodepageRecord;
@@ -57,6 +58,9 @@ import org.apache.poi.util.IOUtils;
* </p>
*/
public class OldExcelExtractor implements Closeable {
+
+ private final static int FILE_PASS_RECORD_SID = 0x2f;
+
private RecordInputStream ris;
// sometimes we hold the stream here and thus need to ensure it is closed at some point
@@ -232,7 +236,9 @@ public class OldExcelExtractor implement
ris.nextRecord();
switch (sid) {
- // Biff 5+ only, no sheet names in older formats
+ case FILE_PASS_RECORD_SID:
+ throw new EncryptedDocumentException("Encryption not supported for Old Excel files");
+
case OldSheetRecord.sid:
OldSheetRecord shr = new OldSheetRecord(ris);
shr.setCodePage(codepage);
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java?rev=1765829&r1=1765828&r2=1765829&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java Thu Oct 20 15:13:16 2016
@@ -32,6 +32,7 @@ import java.io.InputStream;
import java.io.PrintStream;
import org.apache.poi.EmptyFileException;
+import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
@@ -345,10 +346,25 @@ public final class TestOldExcelExtractor
out.close();
}
String string = new String(out.toByteArray(), "UTF-8");
- assertTrue("Had: " + string,
+ assertTrue("Had: " + string,
string.contains("Table C-13--Lemons"));
} finally {
System.setOut(save);
}
}
+
+ @Test
+ public void testEncryptionException() throws Exception {
+ //test file derives from Common Crawl
+ File file = HSSFTestDataSamples.getSampleFile("60284.xls");
+ OldExcelExtractor ex = new OldExcelExtractor(file);
+ assertEquals(5, ex.getBiffVersion());
+ assertEquals(5, ex.getFileType());
+ try {
+ ex.getText();
+ fail();
+ } catch (EncryptedDocumentException e) {
+ assertTrue("correct exception thrown", true);
+ }
+ }
}
Added: poi/trunk/test-data/spreadsheet/60284.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/60284.xls?rev=1765829&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/spreadsheet/60284.xls
------------------------------------------------------------------------------
svn:mime-type = application/vnd.ms-excel
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org