Skip to content

Fix off-by-one bounds check in Tablet.SetValueAt/GetValueAt#168

Open
PDGGK wants to merge 1 commit into
apache:mainfrom
PDGGK:fix/tablet-bounds-off-by-one
Open

Fix off-by-one bounds check in Tablet.SetValueAt/GetValueAt#168
PDGGK wants to merge 1 commit into
apache:mainfrom
PDGGK:fix/tablet-bounds-off-by-one

Conversation

@PDGGK

@PDGGK PDGGK commented Jul 22, 2026

Copy link
Copy Markdown

What

Fix an off-by-one in the index bounds checks of Tablet.SetValueAt and Tablet.GetValueAt.

Problem

Both methods validate columnIndex/rowIndex before indexing the schema/value slices and return an illegal argument error for out-of-range indices. The guards used columnIndex > len(t.measurementSchemas) and rowIndex > t.maxRowNumber. Since measurementSchemas/values have length N and each value slice + timestamps are make([]T, maxRowNumber) (see NewTablet), the valid ranges are 0..N-1 and 0..maxRowNumber-1. Using > lets the exact boundary index (== len, == maxRowNumber) escape the guard, after which measurementSchemas[N] / values[...][maxRowNumber] panics with index out of range instead of returning the intended error. (The existing out-of-range tests use 65535, 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) to TestTablet_SetValueAt / GetValueAt; they panic before the fix and return an error after. go test ./client/ passes; gofmt/vet clean.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant