Bug 51559

Summary: ArrayIndexOutOfBoundsException in 3rd party generated MSG file
Product: POI Reporter: b.geisselmeier
Component: POIFSAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.8-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: files causing the problems
code snippet to reproduce error

Description b.geisselmeier 2011-07-26 10:54:16 UTC
Created attachment 27319 [details]
files causing the problems

In our application we process MS Outlook files (msg) with POIFS.

With the file attached I get various exceptions:

poi-3.2-FINAL
{code}
java.io.IOException: Cannot remove block[ 114 ]; out of range[ 0 - 23 ]
      at org.apache.poi.poifs.storage.BlockListImpl.remove(BlockListImpl.java:104)
      at org.apache.poi.poifs.storage.BlockAllocationTableReader.fetchBlocks(BlockAllocationTableReader.java:190)
      at org.apache.poi.poifs.storage.BlockListImpl.fetchBlocks(BlockListImpl.java:130)
      at org.apache.poi.poifs.filesystem.POIFSFileSystem.processProperties(POIFSFileSystem.java:524)
      at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:176)
{code}

POI-3.8 beta 3 and SVN trunk (rev. 1151057)
{code}
java.lang.ArrayIndexOutOfBoundsException: 0
	at org.apache.poi.poifs.storage.SmallDocumentBlock.getDataInputBlock(SmallDocumentBlock.java:194)
	at org.apache.poi.poifs.filesystem.POIFSDocument.getDataInputBlock(POIFSDocument.java:282)
	at org.apache.poi.poifs.filesystem.ODocumentInputStream.getDataInputBlock(ODocumentInputStream.java:107)
	at org.apache.poi.poifs.filesystem.ODocumentInputStream.<init>(ODocumentInputStream.java:71)
	at org.apache.poi.poifs.filesystem.DocumentInputStream.<init>(DocumentInputStream.java:60)
{code}

I've also attached a code snippet to reproduce this behaviour.

As this msg file is not produced by Outlook itself but by a 3rd party application, I'm not sure if there is a bug in POIFS or if the file is corrupt.
The producer of this application argues that Outlook can open that file, so "it must be correct".

Do you have a hint for me what might be the problem here or possibly a work around?

Thanks a lot,
Benjamin
Comment 1 b.geisselmeier 2011-07-26 10:56:25 UTC
Created attachment 27320 [details]
code snippet to reproduce error
Comment 2 Nick Burch 2011-07-26 21:15:41 UTC
Any chance you could try with NPOIFSFileSystem from POI 3.8 beta 3? Rather than opening a POIFSFileSystem, open a NPOIFSFileSytem, and pass the root of that to HSMF. There's a fair chance it'll work with the new NPOIFS code where it may have previously failed for POIFS
Comment 3 b.geisselmeier 2011-07-28 08:13:30 UTC
Thank you for this hint. With the _N_POIFSFileSytem this file can be accessed.

So I close this issue now and wait for the final release of POI 3.8

Best Regards,
Benjamin