Skip to content

[C++][FlightRPC] ipc::Message::Open reads unaligned Flatbuffers metadata in place #54916

Open

Description

@Spikhalskiy

Describe the bug, including details regarding any error messages, version, and platform.

ipc::Message::Open(metadata, body) verifies and reads the Flatbuffers metadata in place. When the metadata buffer is not 8-byte aligned, every Flatbuffers access is a misaligned load (UB, reported by -fsanitize=alignment).

Flight hits this on every read: DeserializeFlightData slices data_header zero-copy out of the gRPC message (ReadBytesZeroCopy), and FlightData::OpenMessage() passes it straight to Message::Open(). message.cc already has MaybeAlignMetadata() for exactly this ("to avoid potential UBSAN issues from Flatbuffers"), but only MessageDecoder calls it.

Reproduction (on main, built with -fsanitize=alignment): copy a serialized record batch message to an odd address and call ipc::Message::Open() on it. UBSan reports misaligned accesses in VerifyMessage and GetKeyValueMetadata:

flatbuffers/buffer.h:186:20: runtime error: load of misaligned address 0x000756c38081 for type 'uoffset_t' (aka 'unsigned int'), which requires 4 byte alignment
    #3 in arrow::ipc::internal::VerifyMessage(...) metadata_internal.h:190
    #4 in arrow::ipc::Message::MessageImpl::Open() message.cc:90

Suggested fix: call MaybeAlignMetadata(&metadata_) at the start of MessageImpl::Open(). Already-aligned metadata is not copied. (Unaligned bodies are a separate matter, covered by ensure_alignment, #32276.)

Component(s)

C++, FlightRPC

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions