View | Details | Raw Unified | Return to bug 35897
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/record/RecordFactoryInputStream.java (-1 / +18 lines)
Lines 155-160 Link Here
155
155
156
	private boolean _lastRecordWasEOFLevelZero;
156
	private boolean _lastRecordWasEOFLevelZero;
157
157
158
	private boolean _filePassRecordFound;
158
159
159
	/**
160
	/**
160
	 * @param shouldIncludeContinueRecords caller can pass <code>false</code> if loose
161
	 * @param shouldIncludeContinueRecords caller can pass <code>false</code> if loose
Lines 233-239 Link Here
233
            // step underlying RecordInputStream to the next record
234
            // step underlying RecordInputStream to the next record
234
            _recStream.nextRecord();
235
            _recStream.nextRecord();
235
236
236
			r = readNextRecord();
237
            try {
238
                r = readNextRecord();
239
            } catch (RecordFormatException e) {
240
                if (_filePassRecordFound) {
241
                    throw new EncryptedDocumentException(e);
242
                } else {
243
                    throw e;
244
                }
245
            }
237
			if (r == null) {
246
			if (r == null) {
238
				// some record types may get skipped (e.g. DBCellRecord and ContinueRecord)
247
				// some record types may get skipped (e.g. DBCellRecord and ContinueRecord)
239
				continue;
248
				continue;
Lines 292-297 Link Here
292
		if (record instanceof RKRecord) {
301
		if (record instanceof RKRecord) {
293
			return RecordFactory.convertToNumberRecord((RKRecord) record);
302
			return RecordFactory.convertToNumberRecord((RKRecord) record);
294
		}
303
		}
304
		
305
		if (record instanceof FilePassRecord) {
306
		    _filePassRecordFound = true;
307
		    return record;
308
		}
295
309
296
		if (record instanceof MulRKRecord) {
310
		if (record instanceof MulRKRecord) {
297
			Record[] records = RecordFactory.convertRKRecords((MulRKRecord) record);
311
			Record[] records = RecordFactory.convertRKRecords((MulRKRecord) record);
Lines 307-312 Link Here
307
			lastDGRecord.join((AbstractEscherHolderRecord) record);
321
			lastDGRecord.join((AbstractEscherHolderRecord) record);
308
			return null;
322
			return null;
309
		}
323
		}
324
		
325
		
326
		
310
		if (record.getSid() == ContinueRecord.sid) {
327
		if (record.getSid() == ContinueRecord.sid) {
311
			ContinueRecord contRec = (ContinueRecord) record;
328
			ContinueRecord contRec = (ContinueRecord) record;
312
329
(-)src/java/org/apache/poi/EncryptedDocumentException.java (+4 lines)
Lines 21-24 Link Here
21
	public EncryptedDocumentException(String s) {
21
	public EncryptedDocumentException(String s) {
22
		super(s);
22
		super(s);
23
	}
23
	}
24
	
25
	public EncryptedDocumentException(Throwable cause) {
26
	    super(cause);
27
	}
24
}
28
}
(-)src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java (+21 lines)
Lines 22-27 Link Here
22
22
23
import junit.framework.TestCase;
23
import junit.framework.TestCase;
24
24
25
import org.apache.poi.EncryptedDocumentException;
25
import org.apache.poi.POIDataSamples;
26
import org.apache.poi.POIDataSamples;
26
import org.apache.poi.hssf.HSSFTestDataSamples;
27
import org.apache.poi.hssf.HSSFTestDataSamples;
27
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
28
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
Lines 340-343 Link Here
340
341
341
		assertTrue(text.contains("ZIP"));
342
		assertTrue(text.contains("ZIP"));
342
	}
343
	}
344
	
345
	public void testPasswordEncrypted() {
346
        boolean found = false;
347
        try {
348
            createExtractor("password.xls");
349
        } catch (EncryptedDocumentException ede) {
350
            found = true;
351
        }
352
        assertTrue(found);
353
    }
354
	
355
	public void testEncrypted() {
356
	    boolean found = false;
357
	    try {
358
    	    createExtractor("password-hello.xls");
359
	    } catch (EncryptedDocumentException ede) {
360
	        found = true;
361
	    }
362
	    assertTrue(found);
363
	}
343
}
364
}

Return to bug 35897