Bug 47229

Summary: LeftoverDataException with 0x23 Record
Product: POI Reporter: Jonathan Holloway <jonathan.holloway>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: major CC: jonathan.holloway
Priority: P2    
Version: 3.5-dev   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description Jonathan Holloway 2009-05-20 16:45:08 UTC
I get the following exception when trying to read in an Excel document with the following record:

 Offset=0x0000121D(4637) recno=199 sid=0x01AE size=0x000A(10)
     [java] org.apache.poi.hssf.record.SupBookRecord [SUPBOOK External References nSheets=0 url=BLP^CM]
     [java] Offset=0x0000122B(4651) recno=200 sid=0x0023 size=0x005C(92)
     [java] [UNKNOWNRECORD] (0x23)
     [java]   rawData=[E2, 7F, 00, 00, 00, 00, 37, 00, 30, 31, 30, 36, 37, 32, 41, 54, 30, 20, 4D, 55, 4E, 49, 2C, 5B, 52, 54, 47, 5F, 4D, 4F, 4F, 44, 59, 5F, 55, 4E, 44, 45, 52, 4C, 59, 49, 4E, 47, 2C, 52, 54, 47, 5F, 53, 50, 5F, 55, 4E, 44, 45, 52, 4C, 59, 49, 4E, 47, 5D, 01, 00, 00, 02, 09, 00, 00, 23, 4E, 2F, 41, 20, 4E, 2E, 41, 2E, 02, 09, 00, 00, 23, 4E, 2F, 41, 20, 4E, 2E, 41, 2E]
     [java] [/UNKNOWNRECORD]

I've fixed this by changing hasNextRecord in RecordInputStream as follows to read the remaining bytes:

Index: RecordInputStream.java
===================================================================
--- RecordInputStream.java	(revision 776494)
+++ RecordInputStream.java	(working copy)
@@ -121,7 +121,9 @@
 	 */
 	public boolean hasNextRecord() throws LeftoverDataException {
 		if (_currentDataLength != -1 && _currentDataLength != _currentDataOffset) {
-			throw new LeftoverDataException(_currentSid, remaining());
+		    
+			//throw new LeftoverDataException(_currentSid, remaining());
+		    byte[] remainder = readRemainder();
 		}
 		if (_currentDataLength != DATA_LEN_NEEDS_TO_BE_READ) {
 			_nextSid = readNextSid();

I appreciate the exception still needs to be thrown in some cases, I just need to do this in order for it to be more a little more forgiving of weird Excel records.  Just so that you know there might be an issue here.

this is with the 3.5-beta6 (latest SVN code)
Comment 1 Josh Micich 2009-05-21 15:04:31 UTC
Thanks for the hex dump - it made it easy to reproduce this error.

This bug was manifested slightly differently on trunk (A very specific RecordFormatException instead of LeftoverDataException). Somehow you seem to be missing the fix for bug 44792

Fixed in svn r777275
junit added


The sample ExternalNameRecord seems to be a DDE link named '010672AT0 MUNI...'. Are you able to give a quick description of how to create a similar DDE link via the standard Excel GUI?



Regarding your fix for RecordInputStream, this is something you should only ever apply locally (definitely not in production), knowing that POI may silently corrupt Excel files as a a result.  This code used to be very lax, and many bugs reported here were actually obscure downstream effects of POI ignoring unread BIFF record data.