Bug 49237 - [PATCH] java.lang.IndexOutOfBoundsException on row.getRowStyle()
Summary: [PATCH] java.lang.IndexOutOfBoundsException on row.getRowStyle()
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.6-FINAL
Hardware: PC Windows XP
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-30 08:07 UTC by najh
Modified: 2013-11-07 21:57 UTC (History)
0 users



Attachments
Example (19.50 KB, application/vnd.ms-excel)
2010-04-30 08:10 UTC, najh
Details
[PATCH] Bug 49237 - limit xfIndex read to 12 bits (6.61 KB, patch)
2013-11-01 22:33 UTC, Andreas Beeker
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.