Bug 39970 - ArrayIndexOutOfBoundsException when opening EXCEL file
Summary: ArrayIndexOutOfBoundsException when opening EXCEL file
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.5-FINAL
Hardware: All Windows XP
: P5 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2006-07-05 18:18 UTC by Venkatramana Vishwanatham
Modified: 2006-07-26 05:00 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Venkatramana Vishwanatham 2006-07-05 18:18:40 UTC
ArrayIndexOutOfBoundsException Occured when opening EXCEL file that contains 
values in such a way that some values span to other columns but some doesn't 
span to other columns is display.

The error stacktrace is-

	at java.lang.System.arraycopy(Native Method)
	at org.apache.poi.hssf.record.UnknownRecord.<init>
	at org.apache.poi.hssf.record.SubRecord.createSubRecord
	at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
	at org.apache.poi.hssf.record.Record.fillFields(Record.java(Compiled 
	at org.apache.poi.hssf.record.Record.<init>(Record.java(Compiled Code))
	at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
	at java.lang.reflect.Constructor.newInstance(Native Method)
	at org.apache.poi.hssf.record.RecordFactory.createRecord
(RecordFactory.java(Compiled Code))
	at org.apache.poi.hssf.record.RecordFactory.createRecords
(RecordFactory.java(Compiled Code))
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
	at com.mastercard.mcideas.atmdir.util.ExcelUtil.openWorkBook
	at com.mastercard.mcideas.atmdir.util.ExcelUtil.TestReadingWorkBook
	at com.mastercard.mcideas.atmdir.util.ExcelUtil.main

The problem is with System.arrayCopy() method call in UnknownRecord class. A 
fix can be applied to this problem as follows (By making sure the array 
doesn't go beyond limits)

 public UnknownRecord( short id, short size, byte[] data, int offset )
        sid     = id;
        thedata = new byte[size];
        if((data.length - offset) < size)
		size = (short)(data.length - offset);
        System.arraycopy(data, offset, thedata, 0, size);
Comment 1 Jason Height 2006-07-26 12:00:50 UTC
Completely invalid bug, if there is an excel file that is generating this
exception then upload/attach it to a bug report. 

Feel free to repoen this bug, if you can upload the excel causing the troyble.