Skip to content

Cannot access a disposed object (DeflateStream) after recovering from malformed url #1802

Closed
@sergey-tihon

Description

@sergey-tihon

This is almost a duplicate of #1636 but about PowerPoint and with clear repro steps and a sample document.

Describe the bug

Unhandled exception. System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.IO.Compression.DeflateStream'.
   at System.IO.Compression.DeflateStream.ReadCore(Span`1 buffer)
   at System.IO.Packaging.ZipWrappingStream.Read(Span`1 buffer)
   at System.IO.Stream.ReadAtLeastCore(Span`1 buffer, Int32 minimumBytes, Boolean throwOnEndOfStream)
   at System.IO.Stream.ReadAtLeast(Span`1 buffer, Int32 minimumBytes, Boolean throwOnEndOfStream)
   at System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, String baseUriStr, Stream stream, Byte[] bytes, Int32 byteCount, Encoding encoding)
   at System.Xml.XmlTextReaderImpl.FinishInitStream()
   at System.Xml.XmlTextReaderImpl..ctor(Stream stream, Byte[] bytes, Int32 byteCount, XmlReaderSettings settings, Uri baseUri, String baseUriStr, XmlParserContext context, Boolean cl
oseInput)
   at System.Xml.XmlReaderSettings.CreateReader(Stream input, Uri baseUri, String baseUriString, XmlParserContext inputContext)
   at DocumentFormat.OpenXml.XmlConvertingReaderFactory.Create(Stream partStream, IOpenXmlNamespaceResolver resolver, XmlReaderSettings settings, Boolean strictRelationshipFound)
   at DocumentFormat.OpenXml.OpenXmlPartRootElement.LoadFromPart(OpenXmlPart openXmlPart, Stream partStream)
   at DocumentFormat.OpenXml.Packaging.OpenXmlPart.LoadDomTree[T]()
   at DocumentFormat.OpenXml.Packaging.PresentationPart.get_Presentation()
   at Program.<Main>$(String[] args) in /Users/Sergey_Tihon/git/oxml-malformedurl-url/Program.cs:line 7

To Reproduce

  1. clone repo - https://github.com/sergey-tihon/oxml-malformedurl-url
  2. execute dotnet run
using DocumentFormat.OpenXml.Packaging;

using var fs = File.Open("repro.pptx", FileMode.Open, FileAccess.Read);
var openSettings = new OpenSettings { AutoSave = false };
using var doc = PresentationDocument.Open(fs, false, openSettings);

var presentation = doc.PresentationPart!.Presentation!;
var slideIds = presentation.SlideIdList?.ChildElements;
Console.WriteLine(slideIds?.Count ?? -1);
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <RootNamespace>oxml_malformedurl_url</RootNamespace>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="DocumentFormat.OpenXml" Version="3.1.0" />
  </ItemGroup>

</Project>

Observed behavior

Cannot access a disposed object.
Object name: 'System.IO.Compression.DeflateStream'.

Expected behavior

Fully functional recovered document.

Desktop (please complete the following information):

  • OS: macOS v15
  • .NET Target: 8.0.401
  • DocumentFormat.OpenXml Version: 3.1.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions