Bug 11744

Summary: write of empty document corrupts file
Product: POI Reporter: Michael A. Smith <mas>
Component: POIFSAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: major    
Priority: P3    
Version: 1.5.1   
Target Milestone: ---   
Hardware: Other   
OS: All   
Attachments: Outlook (CDF?) expects -2 (end of chain) for empty SBAT propertys' start_block
Unit test

Description Michael A. Smith 2002-08-15 20:19:25 UTC
Problem observed with 1.5.1, 1.7.0, and nightly build 1.8.0-dev-20020813. 

POIFS does not "write" an empty document stream correctly (i.e. a document that
is zero bytes in length).  Failure is observed when trying to read the document
in the form of an IOException with the message of either "Cannot remove block[ 0
]; out of range" or "block[ 0 ] already removed".

Example method to reproduce:

    // construct a new POIFSFileSystem with an empty document
    POIFSFileSystem fs = new POIFSFileSystem();
    fs.getRoot().createDocument("Foo", new ByteArrayInputStream(new byte[0]));
    
    // save the document into a byte array
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    fs.writeFilesystem(out);

    // now try to read the POIFSFileSystem from that byte array.  
    new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));


This was recently posted on poi-dev, but has been added here to make sure the
bug is tracked and not forgotten about.  The post on poi-dev has much more
detail than what's here.  See: 
http://www.mail-archive.com/poi-dev%40jakarta.apache.org/msg03105.html
Comment 1 Anand Palaniswamy 2004-05-24 23:32:21 UTC
Created attachment 11642 [details]
Outlook (CDF?) expects -2 (end of chain) for empty SBAT propertys' start_block
Comment 2 Trejkaz (pen name) 2007-08-27 17:53:17 UTC
Created attachment 20715 [details]
Unit test

I can confirm that Anand's patch fixes the issue, and here is a unit test I
wrote while confirming it.
Comment 3 Nick Burch 2007-12-04 04:56:08 UTC
Patch and test applied, thanks