Host: fix Rectangle.GetHashCode when Left XOR Right is negative#27105
Open
cuiweixie wants to merge 1 commit intoPowerShell:masterfrom
Open
Host: fix Rectangle.GetHashCode when Left XOR Right is negative#27105cuiweixie wants to merge 1 commit intoPowerShell:masterfrom
cuiweixie wants to merge 1 commit intoPowerShell:masterfrom
Conversation
The lower 32-bit fold for negative (Left ^ Right) incorrectly added (UInt64)(-upper) instead of (UInt64)(-lower), mixing the vertical XOR into the horizontal half. Add a CI regression test for Rectangle(-1,0,0,0) whose hash must include the corrected lower contribution.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an arithmetic bug in System.Management.Automation.Host.Rectangle.GetHashCode() so the hash folding uses the correct 32-bit half when (Left ^ Right) is negative, and adds a regression test to prevent reintroduction.
Changes:
- Correct the lower-half negative fold to add
-lower(not-upper) whenlower < 0andlower != Int32.MinValue. - Add a CI-tagged Pester regression test covering
Rectangle(-1, 0, 0, 0).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/System.Management.Automation/engine/hostifaces/MshHostRawUserInterface.cs |
Fixes the incorrect operand used when folding the lower 32-bit half into the 64-bit mix for Rectangle.GetHashCode(). |
test/powershell/Host/HostUtilities.Tests.ps1 |
Adds a targeted regression test validating the corrected hash result for a negative (Left ^ Right) case. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Corrects
Rectangle.GetHashCode()when(Left ^ Right)is negative (and notInt32.MinValue): the lower 32-bit contribution must use-lower, not-upper, so the hash matches the intended mix of vertical and horizontal XOR halves.Changes
MshHostRawUserInterface.cs, use(UInt64)(-lower)in the non-MinValuenegative branch of the lower-half fold.Host.Rectangle.GetHashCodePester test (Tags: CI) forRectangle(-1, 0, 0, 0)(expectedGetHashCode() == 1with the fix).Testing
Invoke-Pesterontest/powershell/Host/HostUtilities.Tests.ps1(newDescribeblock).