Skip to content

fix(#5361): FrameLimits — enforce wire bounds at encode AND decode (no-alloc rejects) - #5372

Merged
qqeasonchen merged 1 commit into
developfrom
fix/5361-frame-bounds
Sep 9, 2026
Merged

qqeasonchen merged 1 commit into
developfrom
fix/5361-frame-bounds

Conversation

@qqeasonchen

Copy link
Copy Markdown
Contributor

What this PR does

Closes #5361 — Phase 1 of the production-HA plan (#5354), acceptance A3: the frame codec enforces wire bounds at BOTH boundaries and rejects malformed input without OOM.

1. The gap this fixes

The codec accepted whatever sizes the header advertised. A hostile frame declaring dataLen = 2^31-1 made the decoder allocate that much memory before failing on the truncated body (OOM instead of a clean reject); truncated buffers escaped as BufferUnderflowException.

2. New FrameLimits (eventmesh-common/wire)

Limit Value
MAX_FRAME_BYTES 16 MiB
MAX_DATA_BYTES 8 MiB
MAX_ATTRIBUTES 64
MAX_ATTR_NAME_BYTES 256 B
MAX_ATTR_VALUE_BYTES 4 KiB

3. Boundary enforcement

  • Encode: attribute count / data length / attr name+value lengths / total encoded size all fail fast — a producer cannot build an oversized frame.
  • Decode: advertised keyCount/dataLen rejected before any allocation; every buffer read (attribute length prefixes, string bodies, data bulk-get) guarded. decode is now total: any byte sequence either decodes or throws IllegalArgumentException — never underflow, never over-allocation.

4. Tests (new FrameLimitsTest, 8 cases)

  • 4 encode-bound rejects + at-the-limit acceptance (boundary is >)
  • Hostile dataLen=Integer.MAX_VALUE on a 64-byte buffer → clean IllegalArgumentException, no allocation
  • Hostile keyCount; dataLen beyond provided buffer
  • Deterministic 20,000-iteration byte-mutation fuzz — every mutant either decodes or throws IllegalArgumentException (the fuzz found and drove the fix for both underflow escapes during development)

Verification (local, Temurin 21.0.11)

:eventmesh-common:test + checkstyle (maxWarnings=0)   BUILD SUCCESSFUL
downstream: runtime + architecture-guard + storage-api tests   BUILD SUCCESSFUL

Relations

Co-authored-by: qqeasonchen qqeasonchen@gmail.com

…o-alloc rejects)

Phase 1 of the production-HA plan (#5354), sub-issue #5361 (acceptance
A3: frame fuzz/boundary tests reject malformed input without OOM).

The gap: the frame codec accepted whatever sizes the header
advertised. A malformed or hostile frame declaring dataLen=2^31-1
made the decoder allocate that much memory before failing on the
truncated body (OOM instead of a clean reject); truncated buffers
escaped as BufferUnderflowException instead of IllegalArgumentException.

New FrameLimits (eventmesh-common/wire):
- MAX_FRAME_BYTES 16 MiB, MAX_DATA_BYTES 8 MiB, MAX_ATTRIBUTES 64,
  MAX_ATTR_NAME_BYTES 256, MAX_ATTR_VALUE_BYTES 4 KiB - generous for
  streaming chunks / large CloudEvents payloads while bounding a
  single frame's memory footprint.

Encode boundary: a producer cannot build an oversized frame
(attribute count, data length, attr name/value length, total encoded
size all fail fast with IllegalArgumentException).

Decode boundary: advertised keyCount/dataLen are rejected BEFORE any
allocation; every buffer read (attribute length prefixes, string
bodies, the data bulk get) is guarded so a truncated frame fails as
IllegalArgumentException - never BufferUnderflowException, never an
over-allocation. decode is now total: any byte sequence either
decodes or throws IllegalArgumentException.

Tests (new FrameLimitsTest, 8 cases):
- 4 encode-bound rejects + at-the-limit acceptance (boundary is >)
- hostile dataLen=Integer.MAX_VALUE on a 64-byte buffer: clean
  IllegalArgumentException, no allocation
- hostile keyCount; dataLen beyond provided buffer
- deterministic 20,000-iteration byte-mutation fuzz: every mutant
  either decodes or throws IllegalArgumentException (found and fixed
  the two underflow escapes above during development)

Local verification (Temurin 21.0.11): common tests + checkstyle
(maxWarnings=0) green; downstream runtime + architecture-guard +
storage-api tests green.

Refs #5361 (sub-issue of #5354).

Co-authored-by: qqeasonchen <qqeasonchen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P0] harden EventMeshFrame: FrameLimits, immutability, fuzz/boundary tests

1 participant