dotnet / Open-XML-SDK

Open XML SDK by Microsoft

Home Page:https://www.nuget.org/packages/DocumentFormat.OpenXml/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug with opening corrupted Open XML documents

BenjaminLopVic opened this issue · comments

Describe the bug
Opening a corrupted document lock the file.

To Reproduce
Steps to reproduce the behavior:

  1. Simulate a corrupted file (simply create a txt file with content in it and change the extension to .docx)
  2. Try opening the file with WordProcessingDocument.Open(...)

Observed behavior
The method WordProcessingDocument.Open(...) throws an exception, stating that the file is corrupted but keeps the file locked to. This can be verified using tools like "File Locksmith."

Expected behavior
Continue throwing the exception but release the file before.

Desktop

  • OS: Windows 11
  • .NET Target: .NET Framework 4.8
  • DocumentFormat.OpenXml Version: 3.0.1

Thanks.

I'm seeing this as well.
Opening the file myself and passing the stream into WordprocessingDocument.Open instead of the path might be a work around.