Skip to content

GH-55479: [C++][FlightRPC] Give gRPC real pb::FlightData messages instead of casting Arrow structs - #55480

Open
Algunenano wants to merge 3 commits into
apache:mainfrom
Algunenano:flight-cfi-casts
Open

Algunenano wants to merge 3 commits into
apache:mainfrom
Algunenano:flight-cfi-casts

Conversation

@Algunenano

@Algunenano Algunenano commented Nov 10, 2026 •

Copy link
Copy Markdown

Rationale for this change

With Clang CFI (-fsanitize=cfi-unrelated-cast), every Flight RPC that sends or receives FlightData fails the CFI check. WritePayload() and ReadPayload() pass a FlightPayload or internal::FlightData to gRPC as a pb::FlightData through reinterpret_cast, and SerializationTraits<pb::FlightData> casts it back. CFI rejects the cast, because the object is not a pb::FlightData. In a build that traps on CFI failures, the RPC aborts. We found this in ClickHouse, which embeds Arrow and is enabling Clang CFI in its release builds as security hardening.

What changes are included in this PR?

gRPC only passes the message to SerializationTraits<pb::FlightData>, which we control. So instead of a cast, WritePayload() and ReadPayload() give gRPC an empty, real pb::FlightData that sits next to a pointer to the Arrow struct, and the traits read the struct back through FlightPayloadOfMessage() and FlightDataOfMessage(). No protobuf message is built or serialized, so the zero-copy path is unchanged.

Are these changes tested?

By the existing arrow-flight-test, built with -flto=thin -fwhole-program-vtables -fvisibility=hidden -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-recover=cfi. Before: all 94 tests pass, with 9 CFI reports on arrow::flight::protocol::FlightData (the 8 casts in serialization_internal.cc, and grpc/impl/call_op_set.h on the same object). After: all 94 tests pass and those reports are gone.

Are there any user-facing changes?

No.

Was AI used for this PR?

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

…es instead of casting Arrow structs

WritePayload() and ReadPayload() passed a FlightPayload or
internal::FlightData to gRPC as a pb::FlightData through
reinterpret_cast, and SerializationTraits<pb::FlightData> cast it back.
The object is not a pb::FlightData, which is undefined behavior and
which Clang CFI (-fsanitize=cfi-unrelated-cast) rejects.

gRPC only passes the message to SerializationTraits, so give it an
empty, real pb::FlightData that sits next to a pointer to the Arrow
struct, and read the struct back from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Both helpers use non-standard-layout offsetof expressions that trigger GCC warnings promoted to errors, breaking default Debug Flight builds.

1 open issue
What changed in this PR

This PR addresses GH-55479 by passing real protobuf FlightData objects to gRPC instead of casting Arrow structs, targeting Clang control-flow integrity failures while preserving Flight’s zero-copy serialization path.

Changes:

  • Wraps protobuf messages alongside pointers to Arrow payloads and receive buffers.
  • Updates serialization traits to retrieve those pointers through new helper functions.
File Description
cpp/​src/​arrow/​flight/​transport/​grpc/​serialization_internal.cc Adds message wrappers and accessors; updates read/write helpers to pass real protobuf objects.
cpp/​src/​arrow/​flight/​transport/​grpc/​customize_grpc.h Declares the accessors and uses them in gRPC serialization traits.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55479 has been automatically assigned in GitHub to PR creator.

offsetof() on the message wrappers, which are not standard-layout, is
conditionally-supported and warns, which fails Debug builds with
-Werror. GCC, Clang and MSVC support it for types without virtual base
classes. The code no longer casts between unrelated types, so
-Wstrict-aliasing does not need to be silenced anymore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 17:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

5 open issues

Review effort: Lite

Guard the -Winvalid-offsetof suppression by compiler instead of by OS,
so that GCC and Clang targeting Windows (MinGW, clang-cl) get it too.
Give the message wrappers a constructor that takes the Arrow struct,
and move the setup shared by the WritePayload() and ReadPayload()
overloads into two templates. Say what Clang CFI rejects instead of
calling the old cast undefined behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 12:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants