HTTP handlers accept negative region_id and start_ts, converting them to large unsigned values
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Description
When `region_id` or `start_ts` is supplied as a negative value via the HTTP status API (e.g. `region_id=-1` or `start_ts=-1`), `strconv.ParseInt` parses it successfully, then the `int64` result gets cast directly to `uint64`. This converts `-1` into `18446744073709551615` (`0xFFFFFFFFFFFFFFFF`), which propagates to `LocateRegionByID` or `GetMvccByStartTs` as an invalid region ID or timestamp.
## Fix
- Replace `strconv.ParseInt` with `strconv.ParseUint` for `region_id` in `RegionHandler.ServeHTTP`
- Replace `strconv.ParseInt` with `strconv.ParseUint` for `start_ts` in `MvccTxnHandler.handleMvccGetByTxn`
- Remove the now-unnecessary `uint64()` cast in both places
`strconv.ParseUint` rejects negative inputs at parse time, so the invalid value never reaches the downstream storage call.
Contributor guide
Research direction
Start with RegionHandler.ServeHTTP and MvccTxnHandler.handleMvccGetByTxn, where the HTTP parameters are parsed before reaching LocateRegionByID or GetMvccByStartTs. Verify that unsigned parsing rejects negative region_id and start_ts values, removes the unnecessary casts, and preserves valid inputs without passing invalid values downstream.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend, databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 75/100