Bug 49237

Summary: [PATCH] java.lang.IndexOutOfBoundsException on row.getRowStyle()
Product: POI Reporter: najh <najh.ru>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: critical    
Priority: P2    
Version: 3.6-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Example
[PATCH] Bug 49237 - limit xfIndex read to 12 bits

Description najh 2010-04-30 08:07:58 UTC
This code rises exception (see attached file):
new HSSFWorkbook(new FileInputStream("2.xls")).getSheetAt(0).getRow(0).getRowStyle();

Exception rises in cases when row has double line border:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 12345, Size: 71
	at java.util.ArrayList.RangeCheck(ArrayList.java:547)
	at java.util.ArrayList.get(ArrayList.java:322)
	at org.apache.poi.hssf.model.WorkbookRecordList.get(WorkbookRecordList.java:50)
	at org.apache.poi.hssf.model.Workbook.getExFormatAt(Workbook.java:787)
	at org.apache.poi.hssf.usermodel.HSSFRow.getRowStyle(HSSFRow.java:575)
Comment 1 najh 2010-04-30 08:10:22 UTC
Created attachment 25385 [details]
Example
Comment 2 Nick Burch 2011-01-14 05:59:24 UTC
Does the problem still occur with a recent nightly build / recent svn checkout?
Comment 3 alex 2012-05-11 09:51:10 UTC
I can verify that this bug still exists in 3.8. I got this error dump:

java.lang.IndexOutOfBoundsException: Index: 8400, Size: 589
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.apache.poi.hssf.model.WorkbookRecordList.get(WorkbookRecordList.java:50)
at org.apache.poi.hssf.model.InternalWorkbook.getExFormatAt(InternalWorkbook.java:832)
at org.apache.poi.hssf.usermodel.HSSFRow.getRowStyle(HSSFRow.java:587)
at org.apache.poi.hssf.usermodel.HSSFRow.getRowStyle(HSSFRow.java:39)
Comment 4 Yegor Kozlov 2012-06-04 12:21:34 UTC
(In reply to comment #3)
> I can verify that this bug still exists in 3.8. I got this error dump:
> 
> java.lang.IndexOutOfBoundsException: Index: 8400, Size: 589
> at java.util.ArrayList.RangeCheck(ArrayList.java:547)
> at java.util.ArrayList.get(ArrayList.java:322)
> at
> org.apache.poi.hssf.model.WorkbookRecordList.get(WorkbookRecordList.java:50)
> at
> org.apache.poi.hssf.model.InternalWorkbook.getExFormatAt(InternalWorkbook.
> java:832)
> at org.apache.poi.hssf.usermodel.HSSFRow.getRowStyle(HSSFRow.java:587)
> at org.apache.poi.hssf.usermodel.HSSFRow.getRowStyle(HSSFRow.java:39)

POI can read the attached file and we have a unit test for it. 
Can you upload a sample file that demonstrates the problem?
Comment 5 Andreas Beeker 2013-11-01 22:33:43 UTC
Created attachment 30993 [details]
[PATCH] Bug 49237 - limit xfIndex read to 12 bits

Currently the RowRecord class tries to read the full 16 bits for the xfIndex, but spec only specifies 12 bits. (see http://msdn.microsoft.com/en-us/library/dd906757(v=office.12).aspx).

In the original test file the higher bits for top and border bottom were also set, so this led to the wrong style index
Comment 6 Nick Burch 2013-11-07 21:57:22 UTC
Thanks for this Andreas. The patch looks good, applied with a few minor tweaks in r1539837.