Author: nick
Date: Mon Sep 19 11:43:09 2011
New Revision: 1172575

URL: http://svn.apache.org/viewvc?rev=1172575&view=rev
Log:
Fix bug #51832 - handle XLS files where the WRITEPROTECT record preceeds the 
FILEPASS one, rather than following as normal

Added:
    poi/trunk/test-data/spreadsheet/51832.xls   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1172575&r1=1172574&r2=1172575&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Sep 19 11:43:09 
2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta5" date="2011-??-??">
+           <action dev="poi-developers" type="fix">51832 - handle XLS files 
where the WRITEPROTECT record preceeds the FILEPASS one, rather than following 
as normal</action>
            <action dev="poi-developers" type="fix">51809 - correct GTE 
handling in COUNTIF</action>
            <action dev="poi-developers" type="add">Add HWPF API to update 
range text and delete bookmarks</action>
            <action dev="poi-developers" type="add">HWPF Bookmarks tables are 
correctly updated on text updates</action>

Modified: 
poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java?rev=1172575&r1=1172574&r2=1172575&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java 
(original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java 
Mon Sep 19 11:43:09 2011
@@ -57,11 +57,26 @@ public final class RecordFactoryInputStr
                        FilePassRecord fpr = null;
                        if (rec instanceof BOFRecord) {
                                _hasBOFRecord = true;
+                               
+                               // Fetch the next record, and see if it 
indicates whether
+                               //  the document is encrypted or not
                                if (rs.hasNextRecord()) {
                                        rs.nextRecord();
                                        rec = 
RecordFactory.createSingleRecord(rs);
                                        recSize += rec.getRecordSize();
                                        outputRecs.add(rec);
+                                       
+                                       // Encrypted is normally BOF then 
FILEPASS
+                                       // May sometimes be BOF, WRITEPROTECT, 
FILEPASS
+                                       if (rec instanceof WriteProtectRecord 
&& rs.hasNextRecord()) {
+                      rs.nextRecord();
+                      rec = RecordFactory.createSingleRecord(rs);
+                      recSize += rec.getRecordSize();
+                      outputRecs.add(rec);
+                                       }
+                                       
+                                       // If it's a FILEPASS, track it 
specifically but
+                                       //  don't include it in the main stream
                                        if (rec instanceof FilePassRecord) {
                                                fpr = (FilePassRecord) rec;
                                                
outputRecs.remove(outputRecs.size()-1);

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=1172575&r1=1172574&r2=1172575&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java 
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Mon Sep 
19 11:43:09 2011
@@ -18,6 +18,8 @@
 package org.apache.poi.hssf.usermodel;
 
 import junit.framework.AssertionFailedError;
+
+import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.hssf.HSSFITestDataProvider;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.OldExcelFormatException;
@@ -2179,4 +2181,16 @@ if(1==2) {
         writeOutAndReadBack(wb);
     }
 
+    /**
+     * Normally encrypted files have BOF then FILEPASS, but
+     *  some may squeeze a WRITEPROTECT in the middle
+     */
+    public void test51832() {
+       try {
+          openSample("51832.xls");
+          fail("Encrypted file");
+       } catch(EncryptedDocumentException e) {
+          // Good
+       }
+    }
 }

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

Propchange: poi/trunk/test-data/spreadsheet/51832.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to