Repository navigation
Conversation
HumanRangesToBitField switched on len(strings.Split(token, "-")), handling only the one-element (a single number) and two-element (an x-y range) cases. A token containing more than one dash, such as "1-2-3", split into three or more elements, matched neither case, and fell through the switch with start and end left at their zero value and a nil error returned - so a malformed range silently resolved to sector 0 instead of being rejected. This is reachable from `lotus-miner sectors numbers reserve [name] [ranges]` (lib/strle used only there), where a mistyped range would create a reservation covering sector 0 rather than failing with a parse error. Add a default case that returns an error for any token that is neither a single number nor an x-y range, plus a test covering malformed inputs.
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
HumanRangesToBitField(lib/strle/human.go) parses a comma-separated list of sector ranges by splitting each token on-and switching on the number of parts, handling only one part (a single number) and two parts (anx-yrange). A token with more than one dash — e.g.1-2-3— splits into three or more parts, matches neithercase, and falls through the switch withstart/endleft at their zero value and anilerror returned, so the malformed input silently resolves to sector 0 instead of being rejected.The one caller is
lotus-miner sectors numbers reserve [name] [ranges](cli/miner/sectors.go:2027), so a mistyped range such as1-2-3would silently create a reservation covering sector 0 rather than failing with a parse error.Fix
Add a
defaultcase to theswitch len(lr)that returns an error for any token that is neither a single number nor anx-yrange.Testing
TestHumanRangesRejectsMalformedcovering1-2-3,1-2-3,5,1--2,1-,-5,a,5-x,"".1-2-3returns anilerror — the bug) and passes with the fix.TestHumanBitfield/TestHumanBitfieldRoundtripstill pass.go test ./lib/strle/,gofmt, andgo vet ./lib/strle/all clean.