Skip to content

[release/10.0] Don't flush data in DeflateStream.FlushAsync if no data was written#121796

Closed
rzikm wants to merge 1 commit intodotnet:release/10.0from
rzikm:121710-gzip-flushasync
Closed

[release/10.0] Don't flush data in DeflateStream.FlushAsync if no data was written#121796
rzikm wants to merge 1 commit intodotnet:release/10.0from
rzikm:121710-gzip-flushasync

Conversation

@rzikm
Copy link
Member

@rzikm rzikm commented Nov 19, 2025

Fixes #121710.

Customer Impact

Certain valid code patterns using DeflateStream and GZipStream may produce invalid bytes when compressing empty input. The invalid output then cannot be correctly decompressed by 3rd party tools.

Workarounds are either not using async path or ensuring FlushAsync is not called by user code if nothing was written to the stream.

  • Customer reported
  • Found internally

Regression

  • Yes
  • No

Behavior differs w.r.t. .NET 8.

The bug has been fixed for .NET 11 by #118570

Testing

Tested scenario reported by customer. Additional validation is provided by CI

Risk

Low, fix is small and the root cause is well understood.

@dotnet-policy-service
Copy link
Contributor

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

@rzikm rzikm changed the title 121710-gzip-flushasync [release/10.0] Don't flush data in DeflateStream.FlushAsync if no data was written Nov 19, 2025
@rzikm rzikm requested a review from a team November 19, 2025 16:14
Copy link
Contributor

Copilot AI left a comment

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 fixes a regression in DeflateStream and GZipStream where calling FlushAsync without writing any data could produce a non-empty partial payload that doesn't decompress correctly. The fix ensures consistency between the sync and async flush implementations.

Key Changes

  • Added if (_wroteBytes) check to the async FlushAsync method to match the existing sync Flush behavior
  • Prevents compression operations when no data has been written to the stream

@karelz karelz added this to the 10.0.x milestone Nov 25, 2025
@rzikm rzikm marked this pull request as draft December 2, 2025 16:00
@rzikm
Copy link
Member Author

rzikm commented Dec 3, 2025

We will not service this change, not enough business justification

@rzikm rzikm closed this Dec 3, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jan 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants