poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From talli...@apache.org
Subject svn commit: r1787846 - in /poi/trunk: src/integrationtest/org/apache/poi/stress/ src/java/org/apache/poi/util/ src/ooxml/testcases/org/apache/poi/poifs/crypt/ test-data/spreadsheet/
Date Mon, 20 Mar 2017 20:47:15 GMT
Author: tallison
Date: Mon Mar 20 20:47:15 2017
New Revision: 1787846

URL: http://svn.apache.org/viewvc?rev=1787846&view=rev
Log:
60881 and 60891 -- on further look, no need to throw an exception for an encrypted xlsb. 
On the second, let's fix readFully to read fully.

Added:
    poi/trunk/test-data/spreadsheet/protected_passtika.xlsb   (with props)
Modified:
    poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java
    poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java?rev=1787846&r1=1787845&r2=1787846&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFBFileHandler.java Mon Mar 20 20:47:15
2017
@@ -33,7 +33,7 @@ public class XSSFBFileHandler extends Ab
 
     static {
         //add expected failures here:
-//        AbstractFileHandler.EXPECTED_EXTRACTOR_FAILURES.add("spreadsheet/Simple.xlsb");
+        AbstractFileHandler.EXPECTED_EXTRACTOR_FAILURES.add("spreadsheet/protected_passtika.xlsb");
     }
 
     @Override

Modified: poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java?rev=1787846&r1=1787845&r2=1787846&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/LittleEndianInputStream.java Mon Mar 20 20:47:15
2017
@@ -28,6 +28,9 @@ import java.io.InputStream;
  * by this class is consistent with that of the inner stream.
  */
 public class LittleEndianInputStream extends FilterInputStream implements LittleEndianInput
{
+
+	private static final int EOF = -1;
+
 	public LittleEndianInputStream(InputStream is) {
 		super(is);
 	}
@@ -128,12 +131,28 @@ public class LittleEndianInputStream ext
     @Override
     public void readFully(byte[] buf, int off, int len) {
         try {
-            checkEOF(read(buf, off, len), len);
+        	checkEOF(_read(buf, off, len), len);
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
     }
 
+    //Makes repeated calls to super.read() until length is read or EOF is reached
+	private int _read(byte[] buffer, int offset, int length) throws IOException {
+    	//lifted directly from org.apache.commons.io.IOUtils 2.4
+		int remaining = length;
+		while (remaining > 0) {
+			int location = length - remaining;
+			int count = read(buffer, offset + location, remaining);
+			if (EOF == count) { // EOF
+				break;
+			}
+			remaining -= count;
+		}
+
+		return length - remaining;
+	}
+
     @Override
     public void readPlain(byte[] buf, int off, int len) {
         readFully(buf, off, len);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java?rev=1787846&r1=1787845&r2=1787846&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java Mon Mar
20 20:47:15 2017
@@ -32,6 +32,7 @@ import org.apache.poi.openxml4j.util.Zip
 import org.apache.poi.poifs.crypt.temp.AesZipFileZipEntrySource;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor;
 import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.xmlbeans.XmlException;
@@ -79,4 +80,40 @@ public class TestSecureTempZip {
         poifs.close();
         fis.close();
     }
+
+    /**
+     * Test case for #59841 - this is an example on how to use encrypted temp files,
+     * which are streamed into POI opposed to having everything in memory
+     */
+    @Test
+    public void protectedXLSBZip() throws IOException, GeneralSecurityException, XmlException,
OpenXML4JException {
+        File tikaProt = XSSFTestDataSamples.getSampleFile("protected_passtika.xlsb");
+        FileInputStream fis = new FileInputStream(tikaProt);
+        POIFSFileSystem poifs = new POIFSFileSystem(fis);
+        EncryptionInfo ei = new EncryptionInfo(poifs);
+        Decryptor dec = ei.getDecryptor();
+        boolean passOk = dec.verifyPassword("tika");
+        assertTrue(passOk);
+
+        // extract encrypted ooxml file and write to custom encrypted zip file
+        InputStream is = dec.getDataStream(poifs);
+
+        // provide ZipEntrySource to poi which decrypts on the fly
+        ZipEntrySource source = AesZipFileZipEntrySource.createZipEntrySource(is);
+
+        // test the source
+        OPCPackage opc = OPCPackage.open(source);
+        String expected = "You can't see me";
+
+        XSSFBEventBasedExcelExtractor extractor = new XSSFBEventBasedExcelExtractor(opc);
+        extractor.setIncludeSheetNames(false);
+        String txt = extractor.getText();
+        assertEquals(expected, txt.trim());
+
+        extractor.close();
+        opc.close();
+        poifs.close();
+        fis.close();
+    }
+
 }

Added: poi/trunk/test-data/spreadsheet/protected_passtika.xlsb
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/protected_passtika.xlsb?rev=1787846&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/protected_passtika.xlsb
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-excel.sheet.binary.macroEnabled.12



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


Mime
View raw message