Bug 33951 - constructor call HSSFWorkbook(POIFSFileSystem) -> IndexOutOfBoundsException / InvocationTargetException
Summary: constructor call HSSFWorkbook(POIFSFileSystem) -> IndexOutOfBoundsException /...
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.5-FINAL
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on: 31114 33082
  Show dependency tree
Reported: 2005-03-10 13:55 UTC by Jens Haertl
Modified: 2005-07-28 20:45 UTC (History)
0 users

POI 2.0 patched origin src (6.02 KB, application/octet-stream)
2005-03-10 13:58 UTC, Jens Haertl
Proposal Solution SystemArrayCopyHelper (2.15 KB, application/octet-stream)
2005-03-10 14:00 UTC, Jens Haertl

Note You need to log in before you can comment on or make changes to this bug.
Description Jens Haertl 2005-03-10 13:55:46 UTC
We decided to create this new bug, although we found bug 31114 and bug 33082
which describe similar problems.

On execution of the following code snippet:

POIFSFileSystem fs = new POIFSFileSystem(request.getServletContext
HSSFWorkbook wb = new HSSFWorkbook (fs);

we get an InvocationTargetException for the createRecord method-call (else
block: retval = new UnknownRecord(rectype, size, data);)  in class

On analysing this call, we found an IndexOutOfBoundsException. The Exception is
thrown on execution of System.arraycopy().

While remote-debugging this scenario: Starting at constructor call till
execution of the arraycopy statement, there was nothing abnormal. 

But on execution of the arraycopy statement, we found the following:

public static void arraycopy( byte[] src, int src_position, byte[] dst, int
dst_position, int length)

- The parameter length did'nt match the available size of parameter src. By
patching the parameter length to: length=Math.min (length,
Math.min(src.length-src_position, dst.length-dst_position)); - we were able to
load the workbook. 

We don't know why in this case these parameters are inconsitent to each other,
but we want to request for help. In the attachment you'll find our patching
class as an proposal solution. 

thx for your help!
Comment 1 Jens Haertl 2005-03-10 13:58:15 UTC
Created attachment 14455 [details]
POI 2.0 patched origin src

Added SystemArrayCopyHelper.arraycopy(thedata, 0, data, 4 + offset,
Comment 2 Jens Haertl 2005-03-10 14:00:25 UTC
Created attachment 14456 [details]
Proposal Solution SystemArrayCopyHelper

Helper manipulation copy length for arraycopy call.
Comment 3 Avik Sengupta 2005-04-22 13:30:38 UTC
Could you possible attach the files that originally caused your problem. This
change may have global effects, so I want some testcases before I check this in. 
Comment 4 Jason Height 2005-07-29 04:45:42 UTC
bug 31114 & bug 33082 are now fixed.

Only reading what is left of a record is a bad thing, usually means that our
implementation is wrong and you dont want to hide these types of bugs because
they will never get fixed.

Given that the referenced bug are fixed, and that there is no attached file to
try, i am going to close this bug.