Bug 11744 - write of empty document corrupts file
Summary: write of empty document corrupts file
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POIFS (show other bugs)
Version: 1.5.1
Hardware: Other All
: P3 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-08-15 20:19 UTC by Michael A. Smith
Modified: 2007-12-04 04:56 UTC (History)
0 users



Attachments
Outlook (CDF?) expects -2 (end of chain) for empty SBAT propertys' start_block (1001 bytes, patch)
2004-05-24 23:32 UTC, Anand Palaniswamy
Details | Diff
Unit test (1.65 KB, text/plain)
2007-08-27 17:53 UTC, Trejkaz (pen name)
Details

Note You need to log in before you can comment on or make changes to this bug.
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