Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0-staging] Revert Deflater/Inflater changes around SafeHandle initialization #88153

Merged

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Jun 28, 2023

Backport of #85001 to release/7.0-staging
Fixes #87791

/cc @ViktorHofer @stephentoub

Customer Impact

Customer reported (Rick Brewster - Paint.NET), see #87791 for more details.

Infrequent application crashes are reported because of an unhandled NullReferenceException when initializing the Deflater or Inflater compression type.

Testing

The fix has been in main since April 19th and we haven't noticed any issues with it.

Risk

Low risk. The code changes are isolated to the two types in question and the overall diff is small. This changes restores the previous .NET 6 behavior around SafeHandle initialization.

Deflater/Inflater's ctor calls a P/Invoke that initializes a SafeHandle.  Previously this was being done to directly initialize a field, but I'd changed that months ago due to it leaving a handle for finalization.  What I failed to notice, however, was that these types themselves defined finalizers, and those finalizers expected that SafeHandle field to have been initialized; now that it's not, if a rare zlib initialization error occurs (e.g. zlib couldn't be found/loaded), the finalizer may crash the process due to an unhandled null reference exception.

For Deflater, it'd be possible to just call GC.SuppressFinalize(this) inside the existing catch block that's disposing of the SafeHandle in the event of an exception.  But it's more complicated for Inflater, where the SafeHandle might be recreated during the Inflater's lifetime, and thus the existing catch block is inside of a helper method that's used from more than just the ctor, and we shouldn't be suppressing finalization in that case.

So, rather than do something complicated for the small gains this provided (it was part of a much larger sweep to clean up non-disposed SafeHandles), I've just reverted these cases.
@ghost
Copy link

ghost commented Jun 28, 2023

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

Issue Details

Backport of #85001 to release/7.0-staging

/cc @ViktorHofer @stephentoub

Customer Impact

Testing

Risk

IMPORTANT: If this backport is for a servicing release, please verify that:

  • The PR target branch is release/X.0-staging, not release/X.0.

  • If the change touches code that ships in a NuGet package, you have added the necessary package authoring and gotten it explicitly reviewed.

Author: github-actions[bot]
Assignees: -
Labels:

area-System.IO.Compression

Milestone: -

@ViktorHofer ViktorHofer added this to the 7.0.x milestone Jun 28, 2023
@carlossanlop
Copy link
Member

carlossanlop commented Jul 10, 2023

@ViktorHofer Reminder: Code Complete for the August Release is tomorrow Monday July 10th. If you intend to include this fix in that release, please make sure to fill out the template, add the servicing-consider label, send the email to Tactics requesting approval. If approved, please switch to the servicing-approved label, and merge it before 4pm because that's when I'll start the staging merge process into internal.

@ViktorHofer ViktorHofer added the Servicing-consider Issue for next servicing release review label Jul 10, 2023
@ViktorHofer ViktorHofer added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Jul 10, 2023
@ViktorHofer ViktorHofer merged commit eacc7bd into release/7.0-staging Jul 10, 2023
2 of 5 checks passed
@ViktorHofer ViktorHofer deleted the backport/pr-85001-to-release/7.0-staging branch July 10, 2023 19:40
@radical radical mentioned this pull request Aug 3, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants