-
Notifications
You must be signed in to change notification settings - Fork 567
Open
Labels
Description
Describe the bug
Reading metadata properties of an Excel file leads to a huge increase of memory while disposing SpreadsheetDocument.
Screenshots
Memory issue on Spreadsheetdocument disposal:
To Reproduce
Minimal repro:
var openSettings = new OpenSettings
{
RelationshipErrorHandlerFactory = package =>
{
return new UriRelationshipErrorHandler();
}
};
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(fs, true, openSettings))
{
//Access main part of document
CustomFilePropertiesPart FileProperties = myDoc.CustomFilePropertiesPart;
if (FileProperties == null)
{
output = MetadataError.ThereAreNoProperties;
return output;
}
// Bug here: Executing this line leads to later issue while disposing 'myDoc'.
DocumentFormat.OpenXml.CustomProperties.Properties props = FileProperties.Properties;
output = MetadataError.Ok;
} // Issue here: this line never returns.
fs.Close(); // Line never reached.
}
Steps to reproduce the behavior:
- Get an Excel file of 100Mb.
- Add any metadata attribute: 'Example' of type 'Text' with value 'MyExampleValue'.
- Execute above code.
- See how memory increases until several Gb and the process hang.
Observed behavior
Memory increases until its limit. Dispose line never returns.
Expected behavior
Memory should not increase and .Disposing the SpreadsheetDocument should not hang the application.
Desktop (please complete the following information):
- OS: [Windows Server 2022 Datacenter Evaluation]
- Office version [N/A]
- .NET Target: reproduced with .NETStandard 2.0 and .NETFramework 4.0
- DocumentFormat.OpenXml Version: Reproduced with 2.12.0 and 2.20.0.
Additional context
Bug also reproducible with 3.3.0 version and next snipet:
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(fs, true))
{
//Access main part of document
CustomFilePropertiesPart FileProperties = myDoc.CustomFilePropertiesPart;
if (FileProperties == null)
{
output = MetadataError.ThereAreNoProperties;
return output;
}
// Bug here: Executing this line leads to later issue while disposing 'myDoc'.
DocumentFormat.OpenXml.CustomProperties.Properties props = FileProperties.Properties;
} // Issue here: this line never returns.
fs.Close(); // Line never reached.
}
The root issue seems to be when opening the document with isEditable = true
.