Skip to content

Decoder: add aggregate message size cap in newMessageReader #61

Description

@the-sarge

What to build

From the 2026-05-27 multi-agent code review (item M6; tracked as F2 in docs/code-review-followups-2026-05-28.md).

newMessageReader performs only a 3-byte header check before field-by-field parsing. Per-field size caps exist (64 KiB AD, 1 KiB sid, etc.) but there is no upfront aggregate length check, so a server calling Respond under a flood of maximally-sized (~66 KiB) malformed messages allocates field-by-field on every call before any cryptographic filter.

Add a maxMessageLen constant derived from the per-field caps plus header overhead (or a documented round constant such as 128 KiB, comfortably above any valid message) and reject longer inputs at the top of newMessageReader with ErrMessage. No valid message length is reduced; this only rejects invalid oversized input earlier.

Acceptance criteria

  • maxMessageLen constant defined and documented (derivation or rationale in a comment)
  • Inputs longer than the cap are rejected before any field parsing, with ErrMessage
  • A maximal valid message still parses; an oversized input is rejected early (both tested)
  • Existing vectors and fuzz targets stay green

Blocked by

None - can start immediately

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/framingWire format / message framingkind/hardeningDefense-in-depth hardening, no API/protocol changepriority/mediumShould land before v1.0.0

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions