Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/dataencode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ void from_wire(Buffer& buf, std::vector<FieldDesc>& descs, TypeStore& cache, uns
{
auto& fld = descs.back();

// bound child count to bytes remaining before reserving (see note in pvaproto.h)
if(nfld.size > (size_t)buf.size())
nfld.size = buf.size();
fld.miter.reserve(nfld.size);
}

Expand Down Expand Up @@ -618,6 +621,9 @@ void from_wire_field(Buffer& buf, TypeStore& ctxt, const FieldDesc* desc, const
case TypeCode::StructA:{
Size alen{};
from_wire(buf, alen);
// bound element count to bytes remaining before allocating (see note in pvaproto.h)
if(alen.size > (size_t)buf.size())
alen.size = buf.size();
shared_array<Value> arr(alen.size);
std::shared_ptr<const FieldDesc> etype(store->top->desc,
&desc->members[0]); // alias
Expand All @@ -635,6 +641,9 @@ void from_wire_field(Buffer& buf, TypeStore& ctxt, const FieldDesc* desc, const
case TypeCode::UnionA: {
Size alen{};
from_wire(buf, alen);
// bound element count to bytes remaining before allocating (see note in pvaproto.h)
if(alen.size > (size_t)buf.size())
alen.size = buf.size();
shared_array<Value> arr(alen.size);
auto cdesc = &desc->members[0];

Expand Down Expand Up @@ -667,6 +676,9 @@ void from_wire_field(Buffer& buf, TypeStore& ctxt, const FieldDesc* desc, const
case TypeCode::AnyA:{
Size alen{};
from_wire(buf, alen);
// bound element count to bytes remaining before allocating (see note in pvaproto.h)
if(alen.size > (size_t)buf.size())
alen.size = buf.size();
shared_array<Value> arr(alen.size);

for(auto& elem : arr) {
Expand Down
5 changes: 5 additions & 0 deletions src/pvaproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ void from_wire(Buffer& buf, shared_array<const void>& varr)
{
Size slen{};
from_wire(buf, slen);
// A valid array cannot contain more elements than there are bytes remaining in the
// message (each element occupies >= 1 byte on the wire). Bound the declared count
// before allocating so a crafted count cannot drive an unbounded allocation.
if(slen.size > (size_t)buf.size())
slen.size = buf.size();
shared_array<E> arr(slen.size);

if(std::is_pod<C>::value) {
Expand Down