<html>
    <head>
      <base href="https://bugs.documentfoundation.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - DocumentFormat.OpenXml cannot open LibreOffice spreadsheet due to FileFormatException in WindowsBase.dll MS.Internal.IO.Zip.ZipIOLocalFileBlock.Validate"
   href="https://bugs.documentfoundation.org/show_bug.cgi?id=128910">128910</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>DocumentFormat.OpenXml cannot open LibreOffice spreadsheet due to FileFormatException in WindowsBase.dll MS.Internal.IO.Zip.ZipIOLocalFileBlock.Validate
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>LibreOffice
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>UNCONFIRMED
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>minor
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Calc
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>libreoffice-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>acrush@mail.ru
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Description:
Hi

I'm developing an application that should process spreadsheets using OpenXml
format and support LibreOffice as well. However, files coming from some
LibreOffice users (<Application>LibreOffice/6.0.7.3$Linux_X86_64
LibreOffice_project/00m0$Build-3</Application>) don't always comply with the
ZIP format specification, and WindowsBase.dll throws a FileFormatException from
the Validate method of this class:
<a href="https://referencesource.microsoft.com/#WindowsBase/Base/MS/Internal/IO/Zip/ZipIOLocalFileBlock.cs,566c718a8927377a">https://referencesource.microsoft.com/#WindowsBase/Base/MS/Internal/IO/Zip/ZipIOLocalFileBlock.cs,566c718a8927377a</a>

Most likely the exception is thrown because this check fails:
GeneralPurposeBitFlag != centralDirFileHeader.GeneralPurposeBitFlag

Looks like bit 11 is not always set correctly in the Central Directory Header.

0000011a: file: xl/sharedStrings.xml           size: 00000000/0/0 (14/808/8/0)
00000329: file: xl/worksheets/_rels/sheet1.xml.rels size: 00000000/0/0
(14/808/8/0)
0000047e: file: xl/worksheets/sheet1.xml       size: 00000000/0/0 (14/808/8/0)
00000a1f: file: xl/workbook.xml                size: 00000000/0/0 (14/808/8/0)
00000c53: file: xl/styles.xml                  size: 00000000/0/0 (14/808/8/0)
00001056: file: docProps/app.xml               size: 00000000/0/0 (14/808/8/0)

000039dc: dir: xl/sharedStrings.xml           off 0000011a, crc/size/size:
2deb184d/461/1728 (14/8/8/0)
00003a1e: dir: xl/worksheets/_rels/sheet1.xml.rels off 00000329, crc/size/size:
696c69ea/260/1069 (14/8/8/0)
00003a6f: dir: xl/worksheets/sheet1.xml       off 0000047e, crc/size/size:
ea23b80c/1371/6163 (14/8/8/0)
00003ab5: dir: xl/workbook.xml                off 00000a1f, crc/size/size:
ed33788b/503/878 (14/8/8/0)
00003af2: dir: xl/styles.xml                  off 00000c53, crc/size/size:
0dd2c718/687/5289 (14/8/8/0)
00003b6b: dir: docProps/app.xml               off 00001056, crc/size/size:
15642684/235/380 (14/8/8/0)

        Bit 11: Language encoding flag (EFS).  If this bit is set,
                the filename and comment fields for this file
                MUST be encoded using UTF-8. (see APPENDIX D)

<a href="https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT">https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT</a>

The file in question can be opened by WinRAR, MS Excel, etc, but not by
DocumentFormat.OpenXml.dll and WindowsBase.dll. If I re-save from Excel, the
updated file will open, but we are trying to avoid this proxy operation if
possible.

I would be very grateful if you advised if this is easily cured by some
application setting in Calc, or provided a fix.


Steps to Reproduce:
1. use DocumentFormat.OpenXml (v2.7.2) via ClosedXml (v0.9.0) as an
implementation of Excel format reader in a .NET console application (targeting
.NET 4.6.1 in my case)
2. try to open the file and enumerate Worksheets
3. fail/succeed depending on some minor implementation detail of the
application saving the file

Actual Results:
   at MS.Internal.IO.Zip.ZipIOLocalFileBlock.Validate(String fileName,
ZipIOCentralDirectoryBlock centralDir, ZipIOCentralDirectoryFileHeader
centralDirFileHeader)
   at MS.Internal.IO.Zip.ZipIOLocalFileBlock.ParseRecord(BinaryReader reader,
String fileName, Int64 position, ZipIOCentralDirectoryBlock centralDir,
ZipIOCentralDirectoryFileHeader centralDirFileHeader)
   at MS.Internal.IO.Zip.ZipIOLocalFileBlock.SeekableLoad(ZipIOBlockManager
blockManager, String fileName)
   at MS.Internal.IO.Zip.ZipIOBlockManager.LoadLocalFileBlock(String
zipFileName)
   at MS.Internal.IO.Zip.ZipArchive.GetFile(String zipFileName)
   at MS.Internal.IO.Zip.ZipArchive.GetFiles()
   at System.IO.Packaging.ZipPackage.ContentTypeHelper..ctor(ZipArchive
zipArchive, IgnoredItemHelper ignoredItemHelper)
   at System.IO.Packaging.ZipPackage..ctor(Stream s, FileMode mode, FileAccess
access, Boolean streaming)
   at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode,
FileAccess packageAccess, Boolean streaming)
   at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(Stream stream,
Boolean readWriteMode)
   at DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(Stream stream,
Boolean isEditable, OpenSettings openSettings)
   at ClosedXML.Excel.XLWorkbook.LoadSheets(Stream stream) in
C:\projects\closedxml\ClosedXML\Excel\XLWorkbook_Load.cs:line 47
   at ClosedXML.Excel.XLWorkbook..ctor(Stream stream) in
C:\projects\closedxml\ClosedXML\Excel\XLWorkbook.cs:line 752
   at IPMS.LegalExpertise.TpcExcelImport.ExcelTpcParser.OpenWorkbook(Byte[]
workbookBytes) in G:\@tfs\...\ETL\Parsers\ITpcFileParser.cs:line 240
   at ....ExcelParser.<Get...FromFile>d__17.MoveNext() in
G:\@tfs\...\ETL\Parsers\ITpcFileParser.cs:line 126

Expected Results:
OpenXml should correctly open Calc files.


Reproducible: Sometimes


User Profile Reset: No



Additional Info:
You can of course consider this Minor, but please don't delay if you can give a
simple advice right away or very soon. Thanks in advance, I appreciate your
time and effort.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>