Description
Describe the bug
When attempting to configure the PackageProperties.Title
attribute of a PresentationDocument
within OpenXML, inserting a string containing the Unicode character \u0001
(often known as a soft hyphen) generates an ArgumentException
. This occurs despite the presence of other valid properties.
Screenshots
None.
To Reproduce
The mini repro code is:
using System;
using (var presentationDocument =
DocumentFormat.OpenXml.Packaging.PresentationDocument.Open("Test.pptx", true))
{
presentationDocument.PackageProperties.Title = "\u0001";
}
The Test.pptx
is any normal pptx file.
You can find all my demo project in https://github.com/lindexi/lindexi_gd/tree/6baba8b5407c1d23119d3ac150b1ab5af4cd810c/Pptx/FukemqibairLaylalljerowhem
Observed behavior
Run my mini repro code, and you can find the exception:
System.ArgumentException:“'�', hexadecimal value 0x01, is an invalid character.”
System.Private.Xml.dll!System.Xml.XmlUtf8RawTextWriter.InvalidXmlChar(int ch, byte* pDst, bool entitize)
System.Private.Xml.dll!System.Xml.XmlUtf8RawTextWriter.WriteElementTextBlock(char* pSrc, char* pSrcEnd)
System.Private.Xml.dll!System.Xml.XmlUtf8RawTextWriter.WriteString(string text)
System.Private.Xml.dll!System.Xml.XmlWellFormedWriter.WriteString(string text)
System.IO.Packaging.dll!System.IO.Packaging.PartBasedPackageProperties.SerializeDirtyProperties()
System.IO.Packaging.dll!System.IO.Packaging.PartBasedPackageProperties.Flush()
System.IO.Packaging.dll!System.IO.Packaging.PartBasedPackageProperties.Close()
System.IO.Packaging.dll!System.IO.Packaging.Package.System.IDisposable.Dispose()
System.IO.Packaging.dll!System.IO.Packaging.Package.Close()
DocumentFormat.OpenXml.Framework.dll!DocumentFormat.OpenXml.Features.StreamPackageFeature.Dispose(bool disposing)
DocumentFormat.OpenXml.Framework.dll!DocumentFormat.OpenXml.Features.StreamPackageFeature.Dispose()
DocumentFormat.OpenXml.Framework.dll!DocumentFormat.OpenXml.Packaging.PackageFeatureCollection.DocumentFormat.OpenXml.Features.IContainerDisposableFeature.Dispose()
DocumentFormat.OpenXml.Framework.dll!DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose(bool disposing)
DocumentFormat.OpenXml.Framework.dll!DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose()
> FukemqibairLaylalljerowhem.dll!Program.<Main>$(string[] args)
Expected behavior
Work well without exception.
Desktop (please complete the following information):
- .NET Target: .NET 9
- DocumentFormat.OpenXml Version: 3.2.0
Additional context
This error throw in dotnet runtime library: https://github.com/dotnet/runtime/blob/c1fe87ad88532f0e80de3739fe7b215e6e1f8b90/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlUtf8RawTextWriter.cs#L932
Reference #1532