Skip to content

fix(arreflect): validate primitive conversion assignment overflow checks#903

Merged
zeroshade merged 2 commits into
apache:mainfrom
fallintoplace:pr/fix-arreflect-overflow
Jul 10, 2026
Merged

fix(arreflect): validate primitive conversion assignment overflow checks#903
zeroshade merged 2 commits into
apache:mainfrom
fallintoplace:pr/fix-arreflect-overflow

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Prevent silent corruption in arreflect primitive conversions by validating numeric assignment bounds before setting through reflection.

Why this fix

setPrimitiveValue used SetInt/SetUint/SetFloat directly for Arrow numeric types. That allowed values outside the target Go type range to wrap/truncate, so bad data could pass through without errors until consumed by fast paths relying on value integrity.

Changes

  • Added explicit overflow checks with:
    • OverflowInt
    • OverflowUint
    • OverflowFloat
  • Return ErrTypeMismatch-wrapped errors on overflow.
  • Preserve existing valid conversion behavior.

Files

  • arrow/array/arreflect/reflect_arrow_to_go.go
  • arrow/array/arreflect/reflect_arrow_to_go_test.go

Validation

  • Added tests for overflow cases:
    • int64 -> int8
    • uint64 -> uint8
    • float64 -> float32

Bug details

  • Severity: 82/100
  • Ask product?: 0/100

@fallintoplace
fallintoplace requested a review from zeroshade as a code owner July 4, 2026 19:51

@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.

Two minor, non-blocking nits on the new FLOAT32 handling — the change itself is a solid defensive improvement and the tests are good.

if v.OverflowFloat(val) {
return fmt.Errorf("cannot set float32 value %f into %s: %w", val, v.Type(), ErrTypeMismatch)
}
v.SetFloat(float64(arr.(*array.Float32).Value(i)))

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.

Minor/consistency: this re-reads arr.(*array.Float32).Value(i) instead of reusing the val computed just above (every other branch uses v.SetInt(val)/v.SetUint(val)/v.SetFloat(val)). Same result, just tidier — v.SetFloat(val).

return fmt.Errorf("cannot set float32 into %s: %w", v.Type(), ErrTypeMismatch)
}
val := float64(arr.(*array.Float32).Value(i))
if v.OverflowFloat(val) {

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.

Minor: for a FLOAT32 source this OverflowFloat check can never trigger — a float32 value widened to float64 always fits a float32 (or float64) destination, so it's effectively dead here, unlike the FLOAT64→float32 case below where it does real work. Harmless; feel free to drop it or leave a one-line note that it's kept for symmetry.

@zeroshade
zeroshade merged commit 5d4c79d into apache:main Jul 10, 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