Fix off-by-one bounds check in Tablet.SetValueAt/GetValueAt#168
Open
PDGGK wants to merge 1 commit into
Open
Conversation
The columnIndex/rowIndex guards used `> len(measurementSchemas)` and `> maxRowNumber`, which let the exact boundary index (columnIndex == len, rowIndex == maxRowNumber) escape the check. Since the schema and value slices have exactly those lengths, the boundary index then hit a runtime "index out of range" panic instead of the intended "illegal argument" error that both methods are meant to return. Change all four guards to `>=`, and add exact-boundary regression cases to TestTablet_SetValueAt / TestTablet_GetValueAt. Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
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.
What
Fix an off-by-one in the index bounds checks of
Tablet.SetValueAtandTablet.GetValueAt.Problem
Both methods validate
columnIndex/rowIndexbefore indexing the schema/value slices and return anillegal argumenterror for out-of-range indices. The guards usedcolumnIndex > len(t.measurementSchemas)androwIndex > t.maxRowNumber. SincemeasurementSchemas/valueshave length N and each value slice +timestampsaremake([]T, maxRowNumber)(seeNewTablet), the valid ranges are0..N-1and0..maxRowNumber-1. Using>lets the exact boundary index (== len,== maxRowNumber) escape the guard, after whichmeasurementSchemas[N]/values[...][maxRowNumber]panics withindex out of rangeinstead of returning the intended error. (The existing out-of-range tests use65535, far past the boundary, so never exercised it.)Fix
Change all four guards from
>to>=.Tests
Added exact-boundary regression cases (
columnIndex == len,rowIndex == maxRowNumber,wantErr: true) toTestTablet_SetValueAt/GetValueAt; they panic before the fix and return an error after.go test ./client/passes;gofmt/vetclean.