Skip to content

Fix dispose state checks - #131647

Draft
alinpahontu2912 wants to merge 1 commit into
dotnet:mainfrom
alinpahontu2912:alinpahontu2912/fix-disposed-state-check-ordering
Draft

Fix dispose state checks#131647
alinpahontu2912 wants to merge 1 commit into
dotnet:mainfrom
alinpahontu2912:alinpahontu2912/fix-disposed-state-check-ordering

Conversation

@alinpahontu2912

Copy link
Copy Markdown
Member

Fix dispose state checks for async Winzipaesstream and zstandarddecoder

@alinpahontu2912 alinpahontu2912 self-assigned this Jul 31, 2026
Copilot AI review requested due to automatic review settings July 31, 2026 14:25
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts disposal-state handling in System.IO.Compression to ensure disposed objects consistently trip ObjectDisposedException checks, including in async disposal paths and in the Zstandard decoder’s early-return logic.

Changes:

  • ZstandardDecoder.Decompress: move the disposed-state check to occur before returning OperationStatus.Done when _finished is already true.
  • WinZipAesStream.DisposeAsync: set _disposed = true inside the finally block to ensure it’s set even when disposal/finalization steps throw.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/libraries/System.IO.Compression/src/System/IO/Compression/Zstandard/ZstandardDecoder.cs Ensures Decompress validates disposed state even on the _finished fast path.
src/libraries/System.IO.Compression/src/System/IO/Compression/WinZipAesStream.cs Ensures async disposal always marks the stream disposed by setting _disposed in finally.

Comment on lines 171 to 176
bytesWritten = 0;
bytesConsumed = 0;

EnsureNotDisposed();

if (_finished)
@alinpahontu2912
alinpahontu2912 marked this pull request as draft July 31, 2026 14:35
@alinpahontu2912 alinpahontu2912 added this to the Future milestone Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants