ASF Bugzilla – Attachment 27101 Details for
Bug 35897
Password protected files
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
A little hack which detects encrypted XLS files
poi-encrypted-xls.patch (text/plain), 3.23 KB, created by
Antoni Mylka
on 2011-06-01 16:12:33 UTC
(
hide
)
Description:
A little hack which detects encrypted XLS files
Filename:
MIME Type:
Creator:
Antoni Mylka
Created:
2011-06-01 16:12:33 UTC
Size:
3.23 KB
patch
obsolete
>Index: src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java >=================================================================== >--- src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java (revision 1130189) >+++ src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java (working copy) >@@ -155,6 +155,7 @@ > > private boolean _lastRecordWasEOFLevelZero; > >+ private boolean _filePassRecordFound; > > /** > * @param shouldIncludeContinueRecords caller can pass <code>false</code> if loose >@@ -233,7 +234,15 @@ > // step underlying RecordInputStream to the next record > _recStream.nextRecord(); > >- r = readNextRecord(); >+ try { >+ r = readNextRecord(); >+ } catch (RecordFormatException e) { >+ if (_filePassRecordFound) { >+ throw new EncryptedDocumentException(e); >+ } else { >+ throw e; >+ } >+ } > if (r == null) { > // some record types may get skipped (e.g. DBCellRecord and ContinueRecord) > continue; >@@ -292,6 +301,11 @@ > if (record instanceof RKRecord) { > return RecordFactory.convertToNumberRecord((RKRecord) record); > } >+ >+ if (record instanceof FilePassRecord) { >+ _filePassRecordFound = true; >+ return record; >+ } > > if (record instanceof MulRKRecord) { > Record[] records = RecordFactory.convertRKRecords((MulRKRecord) record); >@@ -307,6 +321,9 @@ > lastDGRecord.join((AbstractEscherHolderRecord) record); > return null; > } >+ >+ >+ > if (record.getSid() == ContinueRecord.sid) { > ContinueRecord contRec = (ContinueRecord) record; > >Index: src/java/org/apache/poi/EncryptedDocumentException.java >=================================================================== >--- src/java/org/apache/poi/EncryptedDocumentException.java (revision 1130189) >+++ src/java/org/apache/poi/EncryptedDocumentException.java (working copy) >@@ -21,4 +21,8 @@ > public EncryptedDocumentException(String s) { > super(s); > } >+ >+ public EncryptedDocumentException(Throwable cause) { >+ super(cause); >+ } > } >Index: src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java >=================================================================== >--- src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java (revision 1130189) >+++ src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java (working copy) >@@ -22,6 +22,7 @@ > > import junit.framework.TestCase; > >+import org.apache.poi.EncryptedDocumentException; > import org.apache.poi.POIDataSamples; > import org.apache.poi.hssf.HSSFTestDataSamples; > import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey; >@@ -340,4 +341,24 @@ > > assertTrue(text.contains("ZIP")); > } >+ >+ public void testPasswordEncrypted() { >+ boolean found = false; >+ try { >+ createExtractor("password.xls"); >+ } catch (EncryptedDocumentException ede) { >+ found = true; >+ } >+ assertTrue(found); >+ } >+ >+ public void testEncrypted() { >+ boolean found = false; >+ try { >+ createExtractor("password-hello.xls"); >+ } catch (EncryptedDocumentException ede) { >+ found = true; >+ } >+ assertTrue(found); >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 35897
:
15796
|
15797
|
15798
| 27101 |
27102
|
31194
|
31195
|
31389
|
31398
|
31399
|
32208
|
32220
|
32258