← Back to Pull requests

fix(arrow/compute): reject floats at the integer upper bound in safe casts #1691

Closed
unknown closed this pull request without merging on Dec 01, 2026 19:57 UTC
View on GitHub
unknown unknown commented on Nov 27, 2026 03:55 UTC
Author

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?

checkFloatTrunc now 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 by intUpperBound from the existing SizeOf/MinOf helpers. The round-trip comparison still catches fractional values, NaN and values below the minimum. wasTruncMaybeNull now calls wasTrunc instead of repeating its switch.

The float16 branch now does the round trip as float32 instead of comparing float16 bits. Before, a float16 -0.0 failed a safe cast to int32 (0x0000 != 0x8000), while float32 and float64 -0.0 cast to 0. Now all three behave the same.

Not changed: scalar.CastTo for 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/TestFloatingToIntOutOfRange covers 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 → int32 0.

  • On main the new test fails on darwin/arm64 for float32→int32, float32→uint32, float32→int64, float32→uint64, float64→int64, float64→uint64 and the float16 -0.0 case. 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 with assert,test,noasm: ok (darwin/arm64)

  • GOARCH=amd64 go test -short -tags assert,test ./arrow/compute/: ok (under Rosetta)

  • golangci-lint run ./compute/... from arrow/ (v2.13.2): 0 issues
  • Not 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.

    Diff: 316 lines (+237 / -79) across 3 files Reviewer: mansur-akhmadi Review duration: 6722m
    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
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.4% (MEDIUM) · Higher = larger blast radius
    40.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.5% · Safe to merge
    17.5%