fix(arrow/compute): reject floats at the integer upper bound in safe casts #1691
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 316 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.345
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1691"
general
weight: 0.35
mansur-akhmadi
Rationale for this change
Fixes #1690. On arm64, a safe float-to-integer cast of 2^n (the first power of two the target can't hold) returned the integer maximum instead of failing: float64 2^63 → int64 gave 9223372036854775807. The truncation check converts the result back to a float and compares. arm64 saturates out-of-range conversions, and the saturated maximum rounds back to 2^n, so the check passed. amd64 already rejected these inputs.
What changes are included in this PR?
checkFloatTruncnow also rejects inputs at or above 2^n for the target type (2^(bits-1) for signed, 2^bits for unsigned), computed once per call byintUpperBoundfrom the existingSizeOf/MinOfhelpers. The round-trip comparison still catches fractional values, NaN and values below the minimum.wasTruncMaybeNullnow callswasTruncinstead of repeating its switch.The float16 branch now does the round trip as float32 instead of comparing float16 bits. Before, a float16
-0.0failed a safe cast to int32 (0x0000 != 0x8000), while float32 and float64-0.0cast to0. Now all three behave the same.Not changed:
scalar.CastTofor float → int doesn't go through this kernel and doesn't check truncation at all (1.5→1), so that's a separate question.Are these changes tested?
Yes.
TestCasts/TestFloatingToIntOutOfRangecovers the boundary for int32 and uint32 (from float32) and for int64 and uint64 (from float32 and float64), with int8, uint8 and int16 (from float16) as controls. It checks each value on its own and after a null, and checks that the largest representable in-range value and the minimum still cast. It also checks float16-0.0→ int320.-0.0case. With-tags noasm(plain Go conversions instead of the NEON kernel), float32→uint32 already fails on main. With the fix it passes in both modes.go test -short -tags assert,test ./arrow/compute/... ./arrow/scalar/...and the same withassert,test,noasm: ok (darwin/arm64)GOARCH=amd64 go test -short -tags assert,test ./arrow/compute/: ok (under Rosetta)golangci-lint run ./compute/...fromarrow/(v2.13.2): 0 issuesNot checked on a native linux/arm64 runner.
Are there any user-facing changes?
Yes, on arm64 a safe cast of these boundary values now returns an error, the same as on amd64. Unsafe casts (
AllowFloatTruncate) are unchanged.