Validate rowIndex in Tablet.SetTimestamp#169
Open
PDGGK wants to merge 1 commit into
Open
Conversation
SetTimestamp wrote to t.timestamps[rowIndex] without validating rowIndex, so a call with an out-of-range row (e.g. SetTimestamp(ts, 1) on a tablet created with NewTablet(..., 1)) panicked with an index-out-of-range error instead of returning an error. Apply the same bounds check that SetValueAt and GetValueAt use so it returns an "illegal argument rowIndex" error, and add a regression test. Follow-up to apache#168. Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
Contributor
|
Could we preserve the existing Adding an type TimestampSetter interface {
SetTimestamp(int64, int)
}
var _ TimestampSetter = (*client.Tablet)(nil)
var setter func(int64, int) = tablet.SetTimestampSince this module already has v2 releases, keeping |
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
Thanks @HTHou — you noted in #168 that
Tablet.SetTimestampwrites tot.timestamps[rowIndex]without validatingrowIndex, so an out-of-rangerow panics with an index-out-of-range error instead of returning one. For
example, with a tablet created via
NewTablet(..., 1)(only row index 0 isvalid),
SetTimestamp(ts, 1)panics.Fix
Apply the same bounds check
SetValueAtandGetValueAtalready use,returning an
illegal argument rowIndexerror for a negative orout-of-range row:
You noted this needs an API decision, since
SetTimestamphas no errorreturn. I've taken the consistency direction your comment pointed to:
SetTimestampnow returns anerror, matchingSetValueAt/GetValueAt.It is a signature change, but source-compatible for the common
statement-form call — the examples already invoke
SetValueAtthat way —and
go build ./...passes unchanged. If you'd prefer a non-breaking shapeinstead, I'm happy to switch.
Tests
Added
TestTablet_SetTimestampRowIndexBounds: a valid row index returns noerror; out-of-range indices (1 on a one-row tablet, and -1) return an error
instead of panicking.
go build ./...andgo test ./client/pass.Follow-up to #168.