[Libreoffice-bugs] [Bug 128910] New: DocumentFormat.OpenXml cannot open LibreOffice spreadsheet due to FileFormatException in WindowsBase.dll MS.Internal.IO.Zip.ZipIOLocalFileBlock.Validate

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Wed Nov 20 09:26:22 UTC 2019


https://bugs.documentfoundation.org/show_bug.cgi?id=128910

            Bug ID: 128910
           Summary: DocumentFormat.OpenXml cannot open LibreOffice
                    spreadsheet due to FileFormatException in
                    WindowsBase.dll
                    MS.Internal.IO.Zip.ZipIOLocalFileBlock.Validate
           Product: LibreOffice
           Version: unspecified
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Severity: minor
          Priority: medium
         Component: Calc
          Assignee: libreoffice-bugs at lists.freedesktop.org
          Reporter: acrush at mail.ru

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:
https://referencesource.microsoft.com/#WindowsBase/Base/MS/Internal/IO/Zip/ZipIOLocalFileBlock.cs,566c718a8927377a

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)

https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

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.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20191120/8279c2bc/attachment-0001.html>


More information about the Libreoffice-bugs mailing list