Skip to content

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
Copilot finished reviewing on behalf of rzikm November 19, 2025 16:08
@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

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