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

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Bugzilla from bugzilla@apache.org
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: [hidden email]
          Reporter: [hidden email]
  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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 60977] Adding Properties create invalid .xlsx file

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

Javen O'Neal <[hidden email]> changed:

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

--- Comment #1 from Javen O'Neal <[hidden email]> ---
> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 60977] Adding Properties create invalid .xlsx file

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

--- Comment #2 from [hidden email] ---
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 60977] Adding Properties create invalid .xlsx file

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

--- Comment #3 from Javen O'Neal <[hidden email]> ---
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 60977] Adding Properties create invalid .xlsx file

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

--- Comment #4 from Dominik Stadler <[hidden email]> ---
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 60977] Adding Properties create invalid .xlsx file

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=60977

--- Comment #5 from Dominik Stadler <[hidden email]> ---
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: [hidden email]
For additional commands, e-mail: [hidden email]