Summary
MessagePack for C# uses an optional LZ4 decompression path for certain compression modes that can read past the end of the compressed input buffer when given crafted data.
A remote attacker who can send malicious MessagePack payloads may trigger process crashes (denial of service) and, in some cases, cause limited unintended memory disclosure during decompression.
Affected context
This vulnerability arises in .NET applications that use MessagePack for C# with the Lz4Block or Lz4BlockArray compression modes enabled.
It is relevant where untrusted or partially trusted clients can supply MessagePack-encoded payloads that will be decompressed by the server or service.
The issue specifically affects the optional LZ4 decompression path that relies on a deprecated fast-decompression algorithm lacking strict source-length bounds.
Exploit preconditions
- Attack surface: Any API endpoint, message handler, or service boundary that accepts MessagePack data using Lz4Block or Lz4BlockArray compression.
- Required access: Ability to send or inject crafted MessagePack payloads to a vulnerable decompression routine (typically remote network access).
- Trigger point: Decompression of an attacker-controlled message where LZ4 token and length fields are manipulated to extend reads beyond the actual compressed buffer.
- Why exploitation is possible: The LZ4 fast-decompression algorithm does not enforce a strict upper limit on source buffer reads, allowing malformed metadata to drive the decoder to read past the end of the input.
Why this happens
The core issue is improper validation of input parameters in the LZ4 decompression routine.
The implementation uses a deprecated fast-decompression algorithm that assumes well-formed data and does not consistently verify that token-driven length fields remain within the bounds of the compressed source buffer.
This maps to CWE-20: Improper Input Validation, as the decoder trusts attacker-controlled token and length values without robust boundary checks, leading to out-of-bounds reads and undefined behavior such as access violations and potential data exposure.
Potential impact
- Application or service crashes due to
AccessViolationException, resulting in denial of service. - Limited unintended disclosure of memory contents from regions adjacent to the compressed input buffer.
- Disruption of dependent services or background workers that rely on MessagePack for inter-service messaging.
- Increased resource usage and reduced availability while the system recovers from repeated crashes.
General mitigation guidance
Mitigation generally focuses on strengthening input validation and narrowing the exposure of risky decompression paths.
Recommended defensive patterns include:
- Prefer decompression algorithms and modes that enforce strict bounds checking on source and destination buffers.
- Apply conservative defaults by disabling optional compression modes like Lz4Block/Lz4BlockArray when not strictly required, especially on untrusted input paths.
- Introduce validation layers or sanity checks on message envelopes (size limits, type markers, compression flags) before passing data to low-level decompression routines.
- Isolate deserialization and decompression in components with reduced privileges and clear fault boundaries so that failures do not take down critical processes.
- Enforce global request and message size limits to reduce the impact of malformed, oversized, or intentionally adversarial payloads.
How teams detect issues like this
High-level detection approaches can focus on both code and runtime behavior:
- Static analysis and review: Look for usage of Lz4Block/Lz4BlockArray compression in MessagePack configuration, especially in endpoints that consume untrusted data; verify that message size limits and validation are enforced before decompression.
- Security-focused code review: Flag decompression routines derived from or relying on deprecated fast algorithms that lack explicit source-length checks; examine loops where input-driven length fields influence read offsets.
- Runtime monitoring: Track
AccessViolationExceptioncrashes or sudden terminations associated with decompression or deserialization code paths; correlate with unusual or malformed incoming MessagePack traffic. - Automated scanning: Use SAST or dependency-centric tooling to identify projects that enable LZ4 compression modes on external-facing APIs and prioritize them for additional review.

