Browse Source

Fix bug #51832 - handle XLS files where the WRITEPROTECT record preceeds the FILEPASS one, rather than following as normal

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1172575 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_8_BETA5
Nick Burch 12 years ago
parent
commit
29f7fe9eb2

+ 1
- 0
src/documentation/content/xdocs/status.xml View File



<changes> <changes>
<release version="3.8-beta5" date="2011-??-??"> <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="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">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> <action dev="poi-developers" type="add">HWPF Bookmarks tables are correctly updated on text updates</action>

+ 15
- 0
src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java View File

FilePassRecord fpr = null; FilePassRecord fpr = null;
if (rec instanceof BOFRecord) { if (rec instanceof BOFRecord) {
_hasBOFRecord = true; _hasBOFRecord = true;
// Fetch the next record, and see if it indicates whether
// the document is encrypted or not
if (rs.hasNextRecord()) { if (rs.hasNextRecord()) {
rs.nextRecord(); rs.nextRecord();
rec = RecordFactory.createSingleRecord(rs); rec = RecordFactory.createSingleRecord(rs);
recSize += rec.getRecordSize(); recSize += rec.getRecordSize();
outputRecs.add(rec); 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) { if (rec instanceof FilePassRecord) {
fpr = (FilePassRecord) rec; fpr = (FilePassRecord) rec;
outputRecs.remove(outputRecs.size()-1); outputRecs.remove(outputRecs.size()-1);

+ 14
- 0
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java View File

package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;


import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;

import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.OldExcelFormatException; import org.apache.poi.hssf.OldExcelFormatException;
writeOutAndReadBack(wb); 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
}
}
} }

BIN
test-data/spreadsheet/51832.xls View File


Loading…
Cancel
Save