Bug 61286 - can not deal with WriteProtectRecord element
Summary: can not deal with WriteProtectRecord element
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.16-FINAL
Hardware: PC Mac OS X 10.1
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2017-07-13 02:26 UTC by lejingw
Modified: 2017-07-14 13:55 UTC (History)
0 users

the excel to be read (21.00 KB, application/x-ole-storage)
2017-07-13 02:26 UTC, lejingw
the excel to be read with exception (11.50 KB, application/x-ole-storage)
2017-07-14 01:09 UTC, lejingw
consume the remaining bytes (2.07 KB, patch)
2017-07-14 01:17 UTC, lejingw
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description lejingw 2017-07-13 02:26:16 UTC
Created attachment 35124 [details]
the excel to be read

HSSF can not deal with WriteProtectRecord element which is created by MS Excel 97(in the attachment).

the constructor method `WriteProtectRecord(RecordInputStream in)` of class `org.apache.poi.hssf.record.WriteProtectRecord` will not consume the right amount of byte in `org.apache.poi.hssf.record.RecordInputStream#_dataInput`, the amount to be consumed should be equals to `org.apache.poi.hssf.record.RecordInputStream#_currentDataLength`

The exception stack is as follows:

org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x86(WriteProtectRecord) left 2 bytes remaining still to be read.
	at org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:177)
	at org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:234)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:494)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:348)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:405)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:386)
	at poi.HSSFReadWrite.readFile(HSSFReadWrite.java:53)
	at poi.HSSFReadWrite.common(HSSFReadWrite.java:170)
	at poi.HSSFReadWrite.testRead1(HSSFReadWrite.java:293)
Comment 1 Tim Allison 2017-07-13 17:14:59 UTC
This file is identical to the file you shared on 61287.  Would it be possible to re-attach either here or on 61287.  Thank you!
Comment 2 lejingw 2017-07-14 01:09:57 UTC
Created attachment 35134 [details]
the excel to be read with exception
Comment 3 lejingw 2017-07-14 01:17:38 UTC
Created attachment 35135 [details]
consume the remaining bytes

the exception also exist in 3.17-beta1
Comment 4 Tim Allison 2017-07-14 13:55:18 UTC
Thank you!