Bug 19427

Summary: Internal files having names length of 12 cause Excel files to corrupt
Product: POI Reporter: Eric Marcoux <eric_marcoux-qc>
Component: POIFSAssignee: POI Developers List <dev>
Severity: major    
Priority: P3    
Version: 3.0-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Files to reproduce the bug 19427.

Description Eric Marcoux 2003-04-29 13:50:20 UTC

When a form, module, class or sheet in a VBA Project of a Excel file has a 
name length of 12, the file corrupts when saved with the POIFS API. Here is 
the sample code :

FileInputStream fis = new FileInputStream("classeur1.xls");
FileOutputStream fos = new FileOutputStream("classeur2.xls");
POIFSFileSystem p = new POIFSFileSystem(fis);

The problem occurs when a form, module, class or sheet has a name with the 
same length of the "_VBA_PROJECT" internal file (12 characters wide). When 
this occurs, the API place the "_VBA_PROJECT" internal file before the file 
having the same name length in the hierarchy and this seems to cause the 
problem. If I modify the method "compare(Object o1, Object o2)" of the inner 
class "PropertyComparator" of the public class "DirectoryProperty" to return a 
positive (or negative - depending on which parameter "_VBA_PROJECT" is 
passed : o1 or o2) value, the API places the "_VBA_PROJECT" internal file 
after the file resulting in an Excel file readable by MS Excel.

My fix works but I don't think it is a good one (because I am using the 
constant "_VBA_PROJECT" with the "equals" method). Before I submit it, I would 
like to know if there is a better approach because maybe I don't understand 
how the POIFS API is working.

I will attach the following files :
 the "DirectoryProperty.java" fixed class file ;
 the original Excel file (classeur1.xls) containing objects with name length 
of 12 ;
 a corrupt Excel file saved with the original POIFS API (classeur_bad.xls) ;
 a correct Excel file saved with the fix I suggest (classeur2.xls) ;
 and the test class file I use (TestBUG.java) to reproduce the problem.

I use the POI version "1.10.0-dev" (I have tested the case with the 1.8.0 and 
1.5.1 final versions ; they have the same problem too), JDK 1.4.1 on Eclipse 
IDE and Windows Excel XP on a Windows XP machine.

Thanks for your time.

Eric Marcoux...
Comment 1 Eric Marcoux 2003-04-29 13:54:34 UTC
Created attachment 6078 [details]
Files to reproduce the bug 19427.
Comment 2 Andy Oliver 2003-07-24 16:26:04 UTC
This is weird.  I wonder why I don't see this a lot more.  Don't want it to hold
up 2.0 but it should be looked at.
Comment 3 Josh Micich 2008-12-01 22:59:05 UTC
Bug 39234 fix was applied in svn r486265.

*** This bug has been marked as a duplicate of bug 39234 ***