Open-XML-SDK: Open XML SDK ZIP local file header is not compliant to ISO/IEC 29500-2. Incorrect "general purpose bit flag" settings
Describe the bug The currently created XLSX files are not compliant to OpenXML specification ISO/IEC 29500-2. The reason is that in reference to the ZIP Appnote (ZIP File Format Specification Version 6.2.0) and the listed “Requirements on package implementers” in chapter B.4 are not met. What I would like to challenge in particular is the set “General purpose bit flag” of the ZIP local file header. The currently used bit flag is utilizing bit 11, which is unsupported.
Following references are hex representations of the XLSX file… OpenXML SDK used incorrect local file header: 50 4B 03 04 14 00 00 08 08 00 Microsoft Excel used correct file header: 50 4B 03 04 14 00 06 00 08 00
So Microsoft Excel by defaults seems to use “super fast compression” method by default with bit1 and bit2 toggled.
When using .net framework as a target, the headers are written correctly and thus compliant to ISO/IEC 29500-2.
Check out for your reference https://standards.iso.org/ittf/PubliclyAvailableStandards/c077818_ISO_IEC_29500-2_2021(E).zip http://www.pkware.com/documents/APPNOTE/APPNOTE_6.2.0.txt
To Reproduce
using System.IO.Packaging;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
CreateSpreadsheetWorkbook("C:\\Temp\\test.xlsx");
void CreateSpreadsheetWorkbook(string filepath)
{
// Create a spreadsheet document by supplying the filepath.
// By default, AutoSave = true, Editable = true, and Type = xlsx.
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.
Create(filepath, SpreadsheetDocumentType.Workbook);
spreadsheetDocument.CompressionOption = CompressionOption.SuperFast;
// Add a WorkbookPart to the document.
WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
// Add a WorksheetPart to the WorkbookPart.
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
// Add Sheets to the Workbook.
Sheets sheets = spreadsheetDocument.WorkbookPart!.Workbook.
AppendChild<Sheets>(new Sheets());
// Append a new worksheet and associate it with the workbook.
Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.
GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
sheets.Append(sheet);
workbookpart.Workbook.Save();
// Close the document.
spreadsheetDocument.Dispose();
}
Steps to reproduce the behavior:
- Create an empty excel spreadsheet and store it in XLSX
- Check with your favorite HEX file viewer the corresponding local file header
- See that the general purpose flag is set to a unsupported “general purpose bit flag”, where bit 11 is toggled
Expected behavior Give the same correct result for .net Core like for .net framework and thus OpenXML SDK will be compliant to the definitions of ISO_IEC_29500-2. The chosen CompressionOption in the .net code should be correctly considered for the “general purpose bit flag”.
Desktop (please complete the following information):
- OS: Windows
- Office version 16.0.1398.20008
- .NET Target: .NET Core 6
- DocumentFormat.OpenXml Version: 2.20.0)
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (5 by maintainers)
@maedula Yes, it’s going to be available in .NET 8 Preview 6 initially (that version will be shipped on Jul 11th).
If you get a chance to test the fix in that version and confirm it works well, that would be awesome and extremely helpful. We want to wait for the fix to bake in preview first, then if we confirm there are no unexpected issues, we can talk about considering it as a candidate for backporting it into the next servicing releases of 7.0 and 6.0. cc @ericstj