Skip to content

fix(scalar): validate dictionary indices before conversion#927

Merged
zeroshade merged 2 commits into
apache:mainfrom
fallintoplace:fix/dictionary-scalar-index-bounds
Jul 13, 2026
Merged

fix(scalar): validate dictionary indices before conversion#927
zeroshade merged 2 commits into
apache:mainfrom
fallintoplace:fix/dictionary-scalar-index-bounds

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

What

Validate dictionary indices in their native signed or unsigned domain before converting them to int. Use the checked physical index for GetEncodedValue as well, so malformed scalars return an error instead of wrapping on 32-bit or 64-bit platforms.

Tests

  • go test ./arrow/scalar
  • GOOS=linux GOARCH=386 go test -c -o /dev/null ./arrow/scalar
  • pre-commit run golangci-lint-full --all-files

The broader go test ./arrow/... run is otherwise green for the reached packages but the checkout lacks the CSV/parquet fixture directories.

@fallintoplace fallintoplace requested a review from zeroshade as a code owner July 11, 2026 08:00

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice — validating the physical index in its native integer domain before converting to int (physicalIndex) covers the full signed/unsigned int8–int64 set, so wrapped/negative indices no longer reach GetScalar. Routing both ValidateFull and GetEncodedValue through it is clean, and the test matrix (incl. MaxUint64, negatives) is thorough. Two small nits inline.

Comment thread arrow/scalar/nested.go Outdated
}
return int(idx), nil
default:
return 0, fmt.Errorf("unimplemented dictionary type %s", s.DataType())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: report the index type here (dt.IndexType) rather than the whole dictionary type, matching the old GetEncodedValue default. Also consider adding an empty-dictionary (len == 0) out-of-range case to TestDictionaryScalarIndexBounds.

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Centralizing the dictionary scalar index validation with thorough coverage (signed/unsigned/max/negative/out-of-bounds/empty-dictionary) looks good. Thanks!

@zeroshade zeroshade merged commit 950bc29 into apache:main Jul 13, 2026
23 checks passed
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.

2 participants