Bug 41064 - Error when opening an excel file
Summary: Error when opening an excel file
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POIFS (show other bugs)
Version: 3.0-dev
Hardware: PC Windows XP
: P2 normal with 4 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-29 01:42 UTC by Julien Kirch
Modified: 2007-12-04 08:56 UTC (History)
0 users



Attachments
File to reproduce the problem (198.62 KB, application/zip)
2006-12-18 02:25 UTC, Julien Kirch
Details
Patch proposal (1.94 KB, patch)
2006-12-21 02:42 UTC, Julien Kirch
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Kirch 2006-11-29 01:42:23 UTC
Hi, I have a parsing error when trying to read an excel file

Environment : jdk 1.4.2 under Windows XP SP1, error identical under poi
2.0, 2.5.1 and 3.0-alpha2-20060616, parsing an a file created with excel
2002 (containing some french characters) :

HSSFWorkbook hssfWorkbook = new HSSFWorkbook(new POIFSFileSystem(new
BufferedInputStream(new FileInputStream("MyFile.xls"))));

Code worked a few days ago but failed since some changes in the excel file

Error is at
java.lang.StringIndexOutOfBoundsException: String index out of range: 14172
at java.lang.String.checkBounds(String.java:287)
at java.lang.String.<init>(String.java:319)
at org.apache.poi.util.StringUtil.getFromCompressedUnicode(StringUtil.java:163)

original cause is in StringUtil : "return new String(string, offset, len, "ISO-
8859-1");" where string.length - offset > len

As in all other cases len = string.length - offest  I tried to force the len 
value but it gives me a 
org.apache.poi.hssf.record.RecordFormatException: Unhandled Continue Record
	at 
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:185)
so I'm stucked for now	
	
Initial stacktrace : 
	
java.lang.reflect.InvocationTargetException
	at sun.reflect.GeneratedConstructorAccessor9.newInstance(Unknown Source)
	at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
	at 
org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:213)
	at 
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:149)
	at 
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:183)
	at 
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:152)
	at 
com.bnpparibas.grp.framework.testing.testpack.TestPackReader.<init>(TestPackReader.java:114)
	at 
com.bnpparibas.grp.framework.testing.testpack.TestPackReaderTest.testTestPack(TestPackReaderTest.java:13)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at junit.textui.TestRunner.doRun(TestRunner.java:116)
	at 
com.intellij.rt.execution.junit.IdeaTestRunner.doRun(IdeaTestRunner.java:69)
	at junit.textui.TestRunner.doRun(TestRunner.java:109)
	at 
com.intellij.rt.execution.junit.IdeaTestRunner.startRunnerWithArgs(IdeaTestRunner.java:24)
	at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:118)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of 
range: 14172
	at java.lang.String.checkBounds(String.java:287)
	at java.lang.String.<init>(String.java:319)
	at 
org.apache.poi.util.StringUtil.getFromCompressedUnicode(StringUtil.java:163)
	at 
org.apache.poi.hssf.record.StringRecord.fillFields(StringRecord.java:89)
	at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
	at org.apache.poi.hssf.record.StringRecord.<init>(StringRecord.java:51)
	... 32 more

org.apache.poi.hssf.record.RecordFormatException: Unable to construct record 
instance, the following exception occured: null
	at 
org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:226)
	at 
org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:149)
	at 
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:183)
	at 
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:152)
	at 
com.bnpparibas.grp.framework.testing.testpack.TestPackReader.<init>(TestPackReader.java:114)
	at 
com.bnpparibas.grp.framework.testing.testpack.TestPackReaderTest.testTestPack(TestPackReaderTest.java:13)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)


Process finished with exit code -1
Comment 1 Julien Kirch 2006-11-29 01:44:18 UTC
Error in description :

original cause is in StringUtil : "return new String(string, offset, len, "ISO-
8859-1");" where string.length - offset < len
Comment 2 Julien Kirch 2006-12-18 02:25:47 UTC
Created attachment 19279 [details]
File to reproduce the problem

I tried to remove as much unused data as possible from the file but failed to
reduce it to a minimal one.
Comment 3 Julien Kirch 2006-12-21 02:42:14 UTC
Created attachment 19297 [details]
Patch proposal

I tried to fix the problem by limiting the read String then by adding the
following ContinueRecord

It don't break any current testcase and fix my problem
Comment 4 Nick Burch 2007-12-04 08:56:01 UTC
Thanks for this, patch applied