Fix System.OverflowException in WindowChromeWorker._HandleNCHitTest #6779
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #6777
Description
The lParam may be the int 64 value which will throw OverflowException when cast to int 32. We only use the int32 part inside the int64, so it's safe for us to use ToInt64 first and then cast to int32.
And I think this fix is safe. Because the
HandleWmNcHitTestMsg
which handle theNCHitTest
will call theNativeMethods.SignedLOWORD
method. TheSignedLOWORD
will cast to long then cast to int32.wpf/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/NativeMethodsCLR.cs
Lines 6208 to 6210 in 7add0fc
Customer Impact
See #6777
Regression
None.
Testing
Just the CI.
And I pick the code to dotnet-campus/dotnetCampus.CustomWpf#20 and I build the private version to test this by my application.
Risk
Low. It is safe for us to use IntPtr.ToInt64 and cast the long to int.
Microsoft Reviewers: Open in CodeFlow