Bug 47251 - LeftoverDataException: Initialisation of record 0xE2
Summary: LeftoverDataException: Initialisation of record 0xE2
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.5-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-22 11:53 UTC by Jonathan Holloway
Modified: 2014-05-23 14:08 UTC (History)
7 users (show)



Attachments
problematic example spreadsheet (28.26 KB, application/vnd.ms-excel)
2009-12-17 09:00 UTC, Sam Bishop
Details
org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0xE2 left 2 bytes remaining still to be read. (401.04 KB, application/octet-stream)
2011-12-16 14:25 UTC, Andrea Cimini
Details
RecordInputStream.java (FIXED) (14.05 KB, application/octet-stream)
2012-02-24 16:28 UTC, Nicholas Hemley
Details
Problem to process this XLS (182.84 KB, application/x-download)
2012-03-21 19:42 UTC, Ivan
Details
Error Generating File (29.96 KB, application/vnd.ms-excel)
2013-03-12 09:39 UTC, Ankur
Details
Similar issue for this file, Autogenerated (25.50 KB, application/vnd.ms-excel)
2014-04-01 19:55 UTC, Joe Yuan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Holloway 2009-05-22 11:53:46 UTC
I get the following exception:

org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0xE2 left 2 bytes remaining still to be read.
	at org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:124)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:402)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:277)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:202)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:184)

BiffViewer gives me the following exception:

 [java] Offset=0x00000000(0) recno=1 sid=0x0809 size=0x0010(16)
     [java] [BOF RECORD]
     [java]     .version  = 0x0600
     [java]     .type     = 0x0005 (workbook)
     [java]     .build    = 0x15EC
     [java]     .buildyear= 1997
     [java]     .history  = 0x0000C0C1
     [java]     .reqver   = 0x00000306
     [java] [/BOF RECORD]
     [java] 
     [java] [INTERFACEEND]
     [java] [/INTERFACEEND]
     [java] 
     [java] org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0xE2 left 2 bytes remaining still to be read.
     [java]     at org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:124)
     [java]     at org.apache.poi.hssf.dev.BiffViewer.createRecords(BiffViewer.java:70)
     [java]     at org.apache.poi.hssf.dev.BiffViewer.main(BiffViewer.java:398)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [java]     at java.lang.reflect.Method.invoke(Method.java:597)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
     [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
     [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
     [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
     [java]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [java]     at java.lang.reflect.Method.invoke(Method.java:597)
     [java]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
     [java]     at org.apache.tools.ant.Task.perform(Task.java:348)
     [java]     at org.apache.tools.ant.Target.execute(Target.java:357)
     [java]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
     [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
     [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
     [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
     [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
     [java]     at org.apache.tools.ant.Main.runBuild(Main.java:758)
     [java]     at org.apache.tools.ant.Main.startAnt(Main.java:217)
     [java]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
     [java]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
     [java] Discarding 2 bytes and continuing
     [java] Offset=0x00000014(20) recno=2 sid=0x00E2 size=0x0002(2)
     [java] Offset=0x0000001A(26) recno=3 sid=0x00C1 size=0x0002(2)
     [java] [MMS]
     [java]     .addMenu        = 0
     [java]     .delMenu        = 0
     [java] [/MMS]
Comment 1 Yegor Kozlov 2009-05-23 00:02:56 UTC
Can you attach the problem file? 

Yegor
Comment 2 Sam Bishop 2009-12-17 08:59:01 UTC
I am seeing this same problem.  (Especially since the BOF header is exactly the same.)  Here's a bit more detail from the sample file I will be attaching:

Record              Size  Data
------------------  ----  ----
BOF (0809h)         16    00 06 05 00 EC 15 CD 07  C1 C0 00 00 06 03 00 00 
INTERFACEEND (E2h)  2     B0 04 
MMS (C1h)           2     00 00 
INTERFACEEND (E2h)  0
...

The third-party from which we are receiving these problematic spreadsheets used to send us similar, valid ones.  And the second record was INTERFACEHDR (E1h) with the same data payload.

I understand that this is buggy behavior on the part of the program generating these files, but OpenOffice and Excel both open these files without complaint, so it seems reasonable for POI to do so as well.

What I have done for the moment is modify the hasNextRecord() method of the RecordInputStream class, so that it simply skips extra data bytes instead of throwing an exception.  But perhaps an experienced POI developer will have a better idea.

Thank you!
Comment 3 Sam Bishop 2009-12-17 09:00:40 UTC
Created attachment 24728 [details]
problematic example spreadsheet
Comment 4 Yegor Kozlov 2009-12-21 08:25:17 UTC
Thanks for the example. 

It looks like a bug in the Excel generator that produced the problematic file - the second record in the Workbook stream is of type INTERFACEEND (0xE2)  while it should be INTERFACEHDR (0xE1). It can be easily proved if you re-save the file in Excel 2007: the record is preserved but its type is changed from  0xE2 to 0xE1. 

INTERFACEEND is a marker record that has no data. INTERFACEHDR holds a two byte short value. 

Strictly speaking it is an error and violates the spec, but since Excel and OpenOffice can silently read such files, POI should do the same.

The problem should be fixed in r892862 

Yegor
Comment 5 Andrea Cimini 2011-12-16 14:25:58 UTC
Created attachment 28077 [details]
org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0xE2 left 2 bytes remaining still to be read.

problem still persisting with this file
Comment 6 Andrea Cimini 2011-12-16 14:28:08 UTC
the problem still persisting with the new file in attachment
Comment 7 Yegor Kozlov 2011-12-21 13:40:23 UTC
Which version of POI? I had no problems reading the attached file with the latest poi-3.8-beta5.

Yegor

(In reply to comment #6)
> the problem still persisting with the new file in attachment
Comment 8 Nicholas Hemley 2012-02-24 16:28:04 UTC
Created attachment 28380 [details]
RecordInputStream.java (FIXED)

I have added code to RecordInputStream to read to the end of a record instead of throwing an exception when there is left over data.

This works for me since I had the same problem with 3.8beta5 and needed a fix.
Comment 9 b387230 2012-03-09 17:17:03 UTC
Same problem.
Will this be included in the next beta?
Comment 10 Yegor Kozlov 2012-03-11 07:22:23 UTC
(In reply to comment #9)
> Same problem.
> Will this be included in the next beta?

yes, this fix will be included in the next release. 

Yegor
Comment 11 d443006 2012-03-19 17:10:33 UTC
Sorry, just wondering... When should it be fixed?
Comment 12 David Fisher 2012-03-19 17:41:10 UTC
Yegor has the 3.8FINAL release candidate up for a VOTE. You can give it a try to confirm that the fix was included.

http://mail-archives.apache.org/mod_mbox/poi-dev/201203.mbox/%3CCAAwi-j9%3D5kDdBYWx_-eUcVZxTz_57VjPiFOSsDaE0SS-uq3AiQ%40mail.gmail.com%3E
Comment 13 Ivan 2012-03-21 14:38:53 UTC
Same problem with the test release:

Exception in thread "main" org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x10 left 8 bytes remaining still to be read.
	at org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:156)
	at org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:231)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:443)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:285)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:248)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:192)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:327)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:308)
Comment 14 Yegor Kozlov 2012-03-21 15:02:49 UTC
Make sure you are using the latest release of POI. I have no problems reading /writing the attached test file with the latest POI-3.8. 

If you still have the exception, please attach the problematic file. Without a test we can't do much.

Yegor

(In reply to comment #13)
> Same problem with the test release:
> 
> Exception in thread "main"
> org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException:
> Initialisation of record 0x10 left 8 bytes remaining still to be read.
>     at
> org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:156)
>     at
> org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:231)
>     at
> org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:443)
>     at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:285)
>     at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:248)
>     at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:192)
>     at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:327)
>     at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:308)
Comment 15 Ivan 2012-03-21 19:42:44 UTC
Created attachment 28493 [details]
Problem to process this XLS

Here's the XLS file.
Comment 16 Ivan 2012-03-21 19:43:53 UTC
I've attached the file.
Thanks for your help!
Comment 17 Ivan 2012-03-29 13:41:22 UTC
No news on this?
Comment 18 Yegor Kozlov 2012-03-29 13:46:38 UTC
(In reply to comment #17)
> No news on this?

This bug is in my punch list for POI-3.9
Comment 19 Sariq Shaikh 2012-04-01 15:00:14 UTC
I am facing the same issue with auto generated excel file through MSSQL and just curious to know when POI-3.9 will be available ?

Thanks for the great work though.
Comment 20 Matt Rogghe 2012-05-03 15:31:50 UTC
I am seeing the same or similar problem.  Using the 3.8 release (also tested on beta 5). Error seen:

org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x10 left 8 bytes remaining still to be read.
        at org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:156)
        at org.apache.poi.hssf.dev.BiffViewer.createRecords(BiffViewer.java:70)
        at org.apache.poi.hssf.dev.BiffViewer.main(BiffViewer.java:418)
Discarding 8 bytes and continuing

Debug mode in Eclipse running BiffViewer yields the following offending record with surrounding records.  This was run with the --biffhex option.  At the point this is about to throw the exception, the values of pertinent variables:
_currentDataLength: 16
_currentDataOffset: 8
_currentSid: 16

Offset=0x000007B1(1969) recno=65 sid=0x000F size=0x0002(2)
00000000 | 0F 00 02 00 01 00                               | ......          
Offset=0x000007B1(1969) recno=65 sid=0x000F size=0x0002(2)
[REFMODE]
    .mode           = 1
[/REFMODE]

Offset=0x000007B7(1975) recno=66 sid=0x0011 size=0x0002(2)
00000000 | 11 00 02 00 00 00                               | ......          
Offset=0x000007B7(1975) recno=66 sid=0x0011 size=0x0002(2)
[ITERATION]
    .flags      = 0x0000
[/ITERATION]

[DELTA]
    .maxchange = 4.148614224924376E-271
[/DELTA]

Offset=0x000007BD(1981) recno=67 sid=0x0010 size=0x0010(16)
00000000 | 10 00 10 00 00 06 10 00 BB 0D CC 07 3F 50 62 4D | ............?PbM
00000010 | D2 F1 A9 FC                                     | ....            
Offset=0x000007D1(2001) recno=68 sid=0x005F size=0x0002(2)
00000000 | 5F 00 02 00 01 00                               | _.....          
Offset=0x000007BD(1981) recno=67 sid=0x0010 size=0x0010(16)
Offset=0x000007D1(2001) recno=68 sid=0x005F size=0x0002(2)
[SAVERECALC]
    .recalc         = true
[/SAVERECALC]

Offset=0x000007D7(2007) recno=69 sid=0x002A size=0x0002(2)
00000000 | 2A 00 02 00 00 00                               | *.....          
Offset=0x000007D7(2007) recno=69 sid=0x002A size=0x0002(2)
[PRINTHEADERS]
    .printheaders   = false
[/PRINTHEADERS]
Comment 21 Ankur 2013-03-12 09:39:21 UTC
Created attachment 30040 [details]
Error Generating File

I am using Apache POI 3.9, and still getting Error.
Comment 22 Ankur 2013-03-12 09:40:59 UTC
Comment on attachment 30040 [details]
Error Generating File

org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x203 left 4 bytes remaining still to be read.
	at org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:156)
	at org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:231)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:443)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:280)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:243)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:187)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:322)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:303)
	at cerrid.mail.parser.XLSMFileRead.main(XLSMFileRead.java:24)
Comment 23 Phil Persad 2013-03-12 21:13:35 UTC
I just upgraded to poi 3.9 and am still encountering this exception:

org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x23 left 10 bytes remaining still to be read.

Unfortunately I cannot provide the document that causes this exception as I'm working with some very strict confidentiality constraints.
Comment 24 Jijun Wang 2013-09-27 15:41:14 UTC
Tried 3.10-beta2 on Ankur's attachment, still has the same problem.
org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x203 left 4 bytes remaining still to be read.
Comment 25 Joe Yuan 2014-04-01 19:55:52 UTC
Created attachment 31465 [details]
Similar issue for this file, Autogenerated

This file is throwing a similar error for me.  I am using poi-3.10-FINAL

NOTE: the file has been obscured but whatever is causing the exception to be thrown is preserved, the same exception is being thrown before and after obfuscation.  Also the file opens without complaint in excel, and opens fine with poi after resaving via excel.

Here is the exception that is being thrown:

Exception in thread "main" org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x1C left 2 bytes remaining still to be read.
	at org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:156)
	at org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:231)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:480)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:301)
	at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:95)
	at ExcelImporter.EditFileImportDialog.main(EditFileImportDialog.java:415)
Comment 26 Nick Burch 2014-04-01 22:42:00 UTC
Joe - your file seems to be failing on sid=0x001c, which is NoteRecord. If you can, take a look at [MS-XLS] to see how a NoteRecord should be processed, then check (via a hex dump) if your file matches (especially on optional bits!)
Comment 27 Joe Yuan 2014-04-01 23:38:36 UTC
I took a look at a hexdump of the file up against the NoteRecord doc, but to be honest i'm not exactly sure what I am looking for, If you wouldn't mind pointing me in the right direction I would greatly appreciate it.

00000000 D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00 ÐÏ.ࡱ.á........

00000010 00 00 00 00 00 00 00 00 3E 00 03 00 FF FF 09 00 ........>...ÿÿ..
                                             ^~ This is 0x1c
00000020 06 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 ................

Does this byte indicate the start of the NoteRecord or is this is the byte that is "still to be read"?  In light of this, I am more convinced this a bug on the side of the file creation and not POI.  If it is on the creation side and I do not have control of how the file is created, what are my options?

Note Record Doc Page: [http://msdn.microsoft.com/en-us/library/dd905668(v=office.12).aspx]
Comment 28 Nick Burch 2014-04-01 23:46:55 UTC
Try having a look at something like sections 3.2 or 3.8, they might give you a better idea of how to map between the record docs and a stream of bytes

You'll be interested in everything up to the start of the next record
Comment 29 Nick Burch 2014-05-23 14:08:23 UTC
It seems that if the NoteRecord has no author, it may sometimes be double-padded. Fix added in r1597098.