Bug 44536 - Error reading a 'read only 'recommended' XLS file
Summary: Error reading a 'read only 'recommended' XLS file
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-FINAL
Hardware: DEC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-05 02:12 UTC by Richard Evans
Modified: 2008-03-07 03:35 UTC (History)
0 users



Attachments
trivial xls with 'read only recommended' flag set (13.50 KB, application/vnd.ms-excel)
2008-03-06 10:08 UTC, Richard Evans
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Evans 2008-03-05 02:12:02 UTC
This is for version 3.0.2 FINAL.

If you open an XLS file and save with the 'read only recommended' option set, POI fails to read the file:

Exception in thread "main" org.apache.poi.hssf.record.RecordFormatException: Unable to construct record instance
        at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:199)
        at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:117)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:207)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:259)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:240)
        at rde.tests.poi.XLTest.main(XLTest.java:30)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:187)
        ... 5 more
Caused by: java.lang.IllegalArgumentException: Illegal length
        at org.apache.poi.hssf.record.RecordInputStream.readCompressedUnicode(RecordInputStream.java:270)
        at org.apache.poi.hssf.record.FileSharingRecord.fillFields(FileSharingRecord.java:62)
        at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
        at org.apache.poi.hssf.record.FileSharingRecord.<init>(FileSharingRecord.java:48)
        ... 10 more

The code to parse the FILESHARING record does not seem to take account of changes from BIFF5 to BIFF8.  Here is an extract from the openoffice xls file format document:

0 2 1 = Recommend read-only state while loading the file
2 2 Hash value calculated from the read-only password (➜4.18.4)
4 var. User name of the file creator
BIFF2-BIFF5: Byte string, 8-bit string length (➜2.5.2)
BIFF8: Unicode string, 16-bit string length (➜2.5.3)
170

A trivial XLS file is attached
Comment 1 Nick Burch 2008-03-06 07:44:29 UTC
What version of excel did you generate your file with?

(I think all our supported versions of excel ought to be generating biff8 files)
Comment 2 Richard Evans 2008-03-06 07:47:55 UTC
It was Excel 2003.  You are right in that POI supports BIFF8 only, I had not realized that when I posted the original report.  

So it must be that the handling of the FILESHARING record is not quite right.
Comment 3 Nick Burch 2008-03-06 09:51:03 UTC
Could you please upload the problem file, so we can see if it's possible to detect this odd state in the filesharing record?
Comment 4 Richard Evans 2008-03-06 10:08:26 UTC
Created attachment 21641 [details]
trivial xls with 'read only recommended' flag set

Apologies.  Was convinced I had included an attachment with the original report
Comment 5 Nick Burch 2008-03-07 03:35:55 UTC
OK, looks like there was no username set, but there was a username length, so was running off the end of the record

Fix in svn, along with tests, and a new HSSFWorkBook method to test for the read-only flag