Repository navigation
[Cluster] Validate MIGRATE SLOTSRANGE bounds before loop to prevent int overflow hang - #2466
Open
Nguyễn Phúc Hưng Thịnh (nphungthinh2601) wants to merge 2 commits into
Conversation
…nt int overflow hang
Copilot started reviewing on behalf of
Nguyễn Phúc Hưng Thịnh (nphungthinh2601)
December 6, 2026 15:10
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new boundary tests do not exercise either changed break, leaving first-offending-slot reporting and zero migration tasks unverified for multiple non-local slots and overlapping local ranges.
1 open issue
What changed in this PR
Prevents integer-overflow hangs in Garnet’s MIGRATE SLOTSRANGE parser.
Changes:
- Validates range endpoints before iteration.
- Stops at the first non-local or duplicate slot.
- Adds five boundary and extreme-integer regression cases.
| File | Description |
|---|---|
| test/cluster/Garnet.test.cluster.migrate/ClusterMigrateTests.cs | Adds invalid-range regression cases. |
| libs/cluster/Session/MigrateCommand.cs | Checks bounds before looping and preserves the first slot error. |
Review effort: Balanced
This branch has not been deployed
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.

Problem
In
ClusterSession.NetworkTryMIGRATE(libs/cluster/Session/MigrateCommand.cs), theSLOTSRANGEparser validatesClusterConfig.OutOfRange(slot)insidefor (var slot = slotStart; slot <= slotEnd; slot++)rather than before entering the loop (unlikeClusterSession.TryParseSlotsinClusterCommands.cs).When
slotEnd == int.MaxValue(2147483647) and the target resolves to a known peer node,slot++overflows fromint.MaxValuetoint.MinValue, causing the loop to spin indefinitely on the session thread while holding the cluster epoch. Additionally,continueonSLOTNOTLOCALandMULTISLOTREFinside the range loop overwrote earlier errors in the same range instead of reporting the first offending slot.Solution
libs/cluster/Session/MigrateCommand.cs:ClusterConfig.OutOfRange(slotStart)andClusterConfig.OutOfRange(slotEnd)immediately before theforloop (preservingSLOTOUTOFRANGE,slotParseError, and syntax validation of any subsequent range pairs).continuetobreakonSLOTNOTLOCALandMULTISLOTREFinside the range loop soSLOTSRANGEconsistently reports the first offending slot, matchingSLOTSandTryParseSlots.Testing
int.MinValue/int.MaxValuecases (-1 0,0 16384,16384 2147483647,0 2147483647,-2147483648 2147483647) toClusterMigrateRejectsInvalidTransferintest/cluster/Garnet.test.cluster.migrate/ClusterMigrateTests.cs.Release(net10.0, 0 warnings / 0 errors):