Skip to content

[mctp-rs] EOM-bit rebuild can spuriously fail packet serialization under stuffed encodings #845

@dymk

Description

@dymk

From PR #844 review (Copilot):

When end_of_message flips to 1, the transport header is rebuilt and its encoded wire cost may increase under byte-stuffing. Returning an error when rebuilt_header_wire_cost + consumed_wire > max_wire can cause serialization to fail even though it could succeed by reducing the body chunk size and retrying with the EOM header. Consider recomputing chunk sizing using the final header (or iteratively shrinking the last chunk) instead of erroring.

Location: mctp-rs/src/serialize.rs:117

Reachability: PassthroughEncoding (SMBus/eSPI medium): never — header wire-size is constant regardless of EOM bit.

SerialEncoding (opt-in serial feature): possible when the EOM-flipped flags byte happens to encode to 0x7D or 0x7E (which need byte-stuffing → 2 bytes wire instead of 1). The chunking algorithm at the boundary of max_wire could fail rather than retrying with a smaller body.

Workaround: the existing inline comment notes "do not assume" — the error path returns a clear SerializeError("assembly buffer too small after EOM bit set") for diagnosis.

Fix sketch: when rebuilt_header_wire_cost + consumed_wire > max_wire, instead of erroring, shrink the last body chunk by the delta (or iteratively retry with smaller body.len()) and re-emit. Requires non-trivial chunking restructure in MctpPacketContext::serialize_packet.

Scope: out of scope for the source-bump PR #844 (which is a verbatim port of dymk/mctp-rs main @ 1b8b7f5); follow-up against the in-tree source.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions