Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open document fail when Content_Types records paths with wrong case #1355

Open
lindexi opened this issue Mar 7, 2023 · 3 comments
Open

Open document fail when Content_Types records paths with wrong case #1355

lindexi opened this issue Mar 7, 2023 · 3 comments

Comments

@lindexi
Copy link
Member

lindexi commented Mar 7, 2023

Describe the bug

The PresentationDocument.Open will throw the OpenXmlPackageException exception when we open the document which Content_Types records paths with wrong case.

DocumentFormat.OpenXml.Packaging.OpenXmlPackageException:“The document cannot be opened because there is an invalid part with an unexpected content type. 
[Part Uri=/ppt/presProps.xml], 
[Content Type=application/xml], 
[Expected Content Type=application/vnd.openxmlformats-officedocument.presentationml.presProps+xml].”

DocumentFormat.OpenXml.Packaging.OpenXmlPart.Load(DocumentFormat.OpenXml.Packaging.OpenXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart, System.Uri, string, System.Collections.Generic.Dictionary<System.Uri, DocumentFormat.OpenXml.Packaging.OpenXmlPart>)
    DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships(DocumentFormat.OpenXml.Packaging.OpenXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart, DocumentFormat.OpenXml.Packaging.RelationshipCollection, System.Collections.Generic.Dictionary<System.Uri, DocumentFormat.OpenXml.Packaging.OpenXmlPart>)
    DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships(DocumentFormat.OpenXml.Packaging.OpenXmlPackage, DocumentFormat.OpenXml.Packaging.OpenXmlPart, DocumentFormat.OpenXml.Packaging.RelationshipCollection, System.Collections.Generic.Dictionary<System.Uri, DocumentFormat.OpenXml.Packaging.OpenXmlPart>)
    DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load(System.IO.Packaging.Package)
    DocumentFormat.OpenXml.Packaging.PresentationDocument.Open(System.IO.Stream, bool, DocumentFormat.OpenXml.Packaging.OpenSettings)

The [Content_Types].xml records the PartName with wrong case, such as /ppt/presprops.xml what we expect is /ppt/presProps.xml.

And we can open the document with Office PowerPoint, but fail with OpenXMLSDK.

Screenshots

To Reproduce
// Please add a self-contained, minimum viable repro of the issue.
// If you require external resources, please provide a gist or GitHub repro
// An Xunit style test is preferred, but a console application would work too.

Steps to reproduce the behavior:

  1. Download the test file
  2. Use the code to open the test file:
PresentationDocument.Open(testFilePath, false)

Observed behavior
Throw the exception

Expected behavior
The Open XML SDK can open the document file.

Desktop (please complete the following information):

  • OS: any
  • Office version [e.g. 16.0.15427.20178]
  • .NET Target: any
  • DocumentFormat.OpenXml Version: 2.19.0

Additional context

Why the Open XML SDK can not open this document? Because the Open XML SDK will use ZipPackage to get the ContentType, see

https://github.com/dotnet/runtime/blob/2d5a9162f6bd9583981d54363d077a04e4efc868/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs#L604-L624

But the _overrideDictionary does not ignore case, see

https://github.com/dotnet/runtime/blob/2d5a9162f6bd9583981d54363d077a04e4efc868/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs#L694-L699

And it may be fixed in #1295

@tymokvo
Copy link

tymokvo commented Aug 18, 2023

Hello, I believe I just encountered this issue. Is there a workaround based on the linked PR?

The error message is:

DocumentFormat.OpenXml.Packaging.OpenXmlPackageException: The document cannot be opened because there is an invalid part with an unexpected content type. 
[Part Uri=/docMetadata/LabelInfo.xml], 
[Content Type=application/xml], 
[Expected Content Type=application/vnd.ms-office.classificationlabels+xml].

@JaneConan
Copy link

DocumentFormat.OpenXml.Packaging.OpenXmlPackageException:“The document cannot be opened because there is an invalid part with an unexpected content type.
[Part Uri=/xl/styles.xml],
[Content Type=application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml],
[Expected Content Type=application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml].”

@lindexi
Copy link
Member Author

lindexi commented Feb 19, 2024

@JaneConan Sorry, I don't think we have the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants