Skip to content

fix(cli): reject malformed sector number ranges - #13966

Open
parthod0x wants to merge 2 commits into
filecoin-project:masterfrom
parthod0x:fix/strle-reject-malformed-ranges
Open

parthod0x wants to merge 2 commits into
filecoin-project:masterfrom
parthod0x:fix/strle-reject-malformed-ranges

Conversation

@parthod0x

Copy link
Copy Markdown

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 (an x-y range). A token with more than one dash — e.g. 1-2-3 — splits into three or more parts, matches neither case, and falls through the switch with start/end left at their zero value and a nil error 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 as 1-2-3 would silently create a reservation covering sector 0 rather than failing with a parse error.

Fix

Add a default case to the switch len(lr) that returns an error for any token that is neither a single number nor an x-y range.

Testing

  • Added TestHumanRangesRejectsMalformed covering 1-2-3, 1-2-3,5, 1--2, 1-, -5, a, 5-x, "".
  • Confirmed the new test fails on master (1-2-3 returns a nil error — the bug) and passes with the fix.
  • Existing TestHumanBitfield / TestHumanBitfieldRoundtrip still pass.
  • go test ./lib/strle/, gofmt, and go vet ./lib/strle/ all clean.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📌 Triage

Development

Successfully merging this pull request may close these issues.

1 participant