You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2017/04/12 19:13:40 UTC

[Bug 60977] New: Adding Properties create invalid .xlsx file

https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

            Bug ID: 60977
           Summary: Adding Properties create invalid .xlsx file
           Product: POI
           Version: 3.15-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: dev@poi.apache.org
          Reporter: therock@cyberrock.net
  Target Milestone: ---

Created attachment 34909
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=34909&action=edit
Example created file

When adding a custom property, and invalid .xlsx is created.

using the java code:

try (final XSSFWorkbookworkbook = new XSSFWorkbook()) {
   final POIXMLProperties properties = workbook.getProperties();
   final POIXMLProperties.CustomProperties customProperties =
properties.getCustomProperties();
   customProperties.addProperty("Project", project.getName());

   workbook.write(outputStream);

   try (final java.io.FileOutputStream fs = new
java.io.FileOutputStream("C:\\temp\\temp.xlsx")) {
      workbook.write(fs);
   }


 When you try to open temp.xlsx in Excel, you get a "file is corrupted"
warning.

 Upon disassembling the .xlsx file, I found the following incorrect custom.xml
file in docProps:

 <?xml version="1.0" encoding="UTF-8"?>
<Properties
xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"><property
pid="2" fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
name="Project"><vt:lpwstr>test</vt:lpwstr></property></Properties><?xml
version="1.0" encoding="UTF-8"?>
<Properties
xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"><property
pid="2" fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
name="Project"><vt:lpwstr>test</vt:lpwstr></property></Properties>

Note the file seems to be written twice.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60977] Adding Properties create invalid .xlsx file

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

--- Comment #2 from therock@cyberrock.net ---
Ok, I finally had some time to revisit this.  I was calling workbook.write
twice, once to write to a memory stream, and again (only in debug) to save to a
temp file for validation.

I removed the 2nd call and instead just streamed the byte buffer to the temp
file, and it now works properly.

Still seems to me though this is a bug.  Shouldn't you be able to call .write
multiple times without corrupting the spreadsheet?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60977] Adding Properties create invalid .xlsx file

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

Greg Woolsey <gw...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Greg Woolsey <gw...@apache.org> ---
Fixed in trunk revision r1851084.  I hit this yesterday, and it irritated me
enough to track it down.

Turns out POIXMLProperties has multiple write cases depending on internal
state.  In one case only, the one hit by this test/example, it needed to clear
the package part before writing, otherwise it would append the full current
content instead.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60977] Adding Properties create invalid .xlsx file

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |51971


Referenced Bugs:

https://bz.apache.org/bugzilla/show_bug.cgi?id=51971
[Bug 51971] Writing custom properties doesn't work for DOCX and XLSX formats.
-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60977] Adding Properties create invalid .xlsx file

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

Javen O'Neal <on...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from Javen O'Neal <on...@apache.org> ---
> workbook.write(outputStream);
> workbook.write(fs);

Might be because the workbook is being written out twice (which shouldn't be an
issue unless the output streams map to the same file).

Could you try this in the latest trunk build?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60977] Adding Properties create invalid .xlsx file

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

--- Comment #4 from Dominik Stadler <do...@gmx.at> ---
I narrowed this down to MemoryPackagePart accumulating the data across multiple
writes via ZipPackage. However I did not see an easy fix as this is also used
on the read-side and in many other places, so a simple clean in there did not
work...

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60977] Adding Properties create invalid .xlsx file on second write

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

Greg Woolsey <gw...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Adding Properties create    |Adding Properties create
                   |invalid .xlsx file          |invalid .xlsx file on
                   |                            |second write

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60977] Adding Properties create invalid .xlsx file

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Uwe.Herrmann@t-systems.com

--- Comment #6 from Dominik Stadler <do...@gmx.at> ---
*** Bug 61734 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60977] Adding Properties create invalid .xlsx file

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

--- Comment #3 from Javen O'Neal <on...@apache.org> ---
Were the 2 streams that you wrote to connected in some way?

Can you post a short example of what you were doing, specifically the opening
of the workbook, the creation of each OutputStream and the closure of the
workbook and both output streams?

If you read the workbook in from a file, was that the same file as one of the
output streams.

I'm trying to get an idea where we should start for unit testing this. I agree
that concatenating the contents of an xml file twice should not happen and
result in an error, so long as it's within POI's ability to do so.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 60977] Adding Properties create invalid .xlsx file

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

--- Comment #5 from Dominik Stadler <do...@gmx.at> ---
Created attachment 35357
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=35357&action=edit
Reproducing testcase, open the resulting files

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org