question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Open XML SDK ZIP local file header is not compliant to ISO/IEC 29500-2. Incorrect "general purpose bit flag" settings

See original GitHub issue

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:

  1. Create an empty excel spreadsheet and store it in XLSX
  2. Check with your favorite HEX file viewer the corresponding local file header
  3. 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)

Issue Analytics

  • State:open
  • Created 3 months ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
carlossanlopcommented, Jun 22, 2023

@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

0reactions
maedulacommented, Jul 13, 2023

@ericstj issue is created in dotnet/runtime. Not sure how to proceed here for this issue. If it is up to me, we can get this closed as resolved

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not load file or assembly 'DocumentFormat.OpenXml
It's an assembly - it doesn't just appear out of the ether. You'll need to download or install it appropriately. I'd just use...
Read more >
Untitled
Command line show open files, Select text in pdf ios? Karpoor gauram mp3 life ok serial watch, Vueling landing song quotes. Tu jaruri...
Read more >
ZIP File Format (PKWARE)
A ZIP file is a package containing one or more files, usually compressed and sometimes encrypted. The basic structure consists of a sequence...
Read more >
ZIP (file format)
ZIP is an archive file format that supports lossless data compression. A ZIP file may contain one or more files or directories that...
Read more >
OWS Context evaluation IP Engineering Report - OGC Portal
In the XML Schema Documents specified herein, these parameters are encoded with the xsd:string type, which does NOT require that these strings not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found