Bug 30783

Summary: Protected Workbook Read Error
Product: POI Reporter: chang.zhao
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED WONTFIX    
Severity: major    
Priority: P3    
Version: 2.5-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description chang.zhao 2004-08-21 03:36:32 UTC
Create a new Excel Document, select tools->protect workbook, and type in a 
password.
This will cause

POIFSFileSystem fs = new POIFSFileSystem(i);
HSSFWorkbook wb = new HSSFWorkbook(fs); <=

to fail.

Upon investigation of this bug, it seems that a protected workbook (but not a 
protected sheet) will cause the system to report length inaccurately:

i.e. in FontRecord 
fillFields(byte [] data, short size, int offset)
...
 field_10_font_name_len      = data[ 14 + offset ];
...

on an unprotected workbook would give a sane value like 5.  However, on a 
protected workbook it would report a wierd value like 49.  I believe the 
previous bugs with ArrayOutofBoundsException s might be related to this 
incorrect length reporting.  This is not limited to length, other fields are 
going insane as well.

Further, further investigation turns out that protected workbooks have an extra 
record of type 47, length 56 right between BOF and InterfaceHeader, and it 
looks like every record after that record (including the interfaceheader) got 
everything scambled.


On a related note,  as I was looking at FontRecord.java, in 
fillFields(byte [] data, short size, int offset)

if (data[ 15 ] == 0) {   // is compressed unicode
    field_11_font_name = StringUtil.getFromCompressedUnicode(data, 16,
        LittleEndian.ubyteToInt(field_10_font_name_len));
}

should perhaps be
if (data[ 15 + offset] == 0) {
    field_11_font_name = StringUtil.getFromCompressedUnicode(data, 16 + offset,
         LittleEndian.ubyteToInt(field_10_font_name_len));

}

?  Or is there any reason that offset shouldn't be added?

Thanks,


CZ
Comment 1 Glen Stampoultzis 2004-09-19 01:34:09 UTC
We're not planning support for protected workbooks at this stage (it's in the
FAQ I believe).  It is unclear to us from a legal point of view whether we're
allowed to tackle decrypting protected workbooks so we're playing it safe.  If
you wish to independently tackle this feel free but unless we can get a clear
ruling on this it's probably not going to make it into POI proper.