Bug 45777 - header overflow
Summary: header overflow
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-dev
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Keywords: ErrorMessage
Depends on:
Reported: 2008-09-11 04:42 UTC by Kolobok
Modified: 2009-06-03 20:57 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Kolobok 2008-09-11 04:42:29 UTC
When header length more than 255 symbols (maximum allowed by xls format) java.lang.ArrayIndexOutOfBoundsException occures

HSSFWorkbook workBook = new HSSFWorkbook();
HSSFSheet sheet = workBook.createSheet("Sheet 1");

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at org.apache.poi.util.StringUtil.putUnicodeLE(StringUtil.java:208)
	at org.apache.poi.hssf.record.HeaderRecord.serialize(HeaderRecord.java:179)
	at org.apache.poi.hssf.model.Sheet.serialize(Sheet.java:825)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:1188)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1118)
	at poiutils.HSSFUtils.flushWorkBook(HSSFUtils.java:170)
	at POITest.main(POITest.java:45)
Comment 1 Nick Burch 2008-09-11 05:34:35 UTC
Any thoughts on what would be a logical exception to throw instead? Perhaps IllegalArgumentException or IllegalStateException

I think picking the right exception may well be harder than detecting the situation and throwing it :)
Comment 2 Nick Burch 2008-09-21 10:38:38 UTC
IllegalArgumentException is now thrown at the right point
Comment 3 Josh Micich 2009-06-03 19:02:52 UTC
svn r697559

Comment 4 Josh Micich 2009-06-03 20:57:03 UTC
This bug was probably mis-diagnosed.  Excel handles header / footer text longer than 256 bytes, and none of the documentation mentions this limit.

Prior to the introduction of StandardRecord (and LittleEndian input/output refactoring of the BIFF serialization) this code was much more fragile.  It's likely that the original bug was fixed through all that work.

As of the fix for bug 47244, POI now allows header / footer text much longer than 256 bytes.  POI enforces a limit of 8221 bytes.  I am not sure if this is the absolute max, but it avoids the need for BIFF record continuation logic.