Repository navigation
Conversation
The typed-data deserializers read an element/field count from the wire and then allocate (new[] / reserve) from it before reading any element data, without bounding the declared count against the bytes remaining in the message. A small message that declares a very large count therefore drives a correspondingly large allocation. Since each encoded element occupies at least one byte on the wire, a valid count can never exceed the bytes remaining, so clamp the declared count to buf.size() before allocating. This is a no-op for well-formed messages. Affected sites: the array decode in pvaproto.h (shared_array), and the struct child-count reserve and the StructA/UnionA/AnyA array decoders in dataencode.cpp.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The typed-data deserializers read an element/field count off the wire and then allocate
(
new[]/reserve) from it before reading any element data, without bounding the declaredcount against the bytes remaining in the message. A small message that declares a very large
array/field count therefore drives a correspondingly large allocation.
This PR clamps each declared count to
buf.size()before allocating. Since every encoded elementoccupies at least one byte on the wire, a valid count can never exceed the bytes remaining, so this
is a no-op for well-formed messages.
Sites bounded:
src/pvaproto.h— array decodeshared_array<E> arr(slen.size)src/dataencode.cpp— struct child-countreserve(nfld.size), and theStructA/UnionA/AnyAarray decodersshared_array<Value> arr(alen.size)Context / reachability
Reached via
from_wire_type_value, whichServerConn::handle_CONNECTION_VALIDATION()calls on theclient-supplied
authvalue during the initial handshake (before authentication). The message body isbounded by the header
len, but the declared count inside the body is independent oflen.Measured impact (low — this is hardening, not a reported DoS)
On a 64-bit host with memory overcommit (a typical IOC) the oversized
new[]is a lazy reservationthat never commits: a ~9-byte input requesting ~8 GB completes in ~17 ms at ~33 MB peak RSS, because
the element-read loop only touches the bytes the message actually carries. On a host with overcommit
disabled or a tight
ulimitthe allocation instead throwsstd::bad_alloc. I am not claiming apractical denial of service — this is an unbounded-allocation-from-declared-count pattern (CWE-770)
that is cheap to bound. (One thing I did not verify: on a 32-bit target
count * sizeof(E)couldoverflow
size_tand under-allocate; worth a glance.)How it was found
Coverage-guided fuzzing (libFuzzer + ASan/UBSan) of
pvxs::impl::from_wire_type_valuein isolation.After adding these bounds, a re-fuzz of the full decode path (dataencode / data / bitmask / type /
sharedarray) over tens of millions of executions found no memory-safety issues.
Tested against current master (
4311a85). Happy to adjust the approach (e.g. reject vs. clamp) to yourpreference.