MCPcopy Create free account
hub / github.com/ElementsProject/elements / Unser

Method Unser

src/serialize.h:597–615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

595
596 template<typename Stream, typename V>
597 void Unser(Stream& s, V& v)
598 {
599 Formatter formatter;
600 v.clear();
601 size_t size = ReadCompactSize(s);
602 size_t allocated = 0;
603 while (allocated < size) {
604 // For DoS prevention, do not blindly allocate as much as the stream claims to contain.
605 // Instead, allocate in 5MiB batches, so that an attacker actually needs to provide
606 // X MiB of data to make us allocate X+5 Mib.
607 static_assert(sizeof(typename V::value_type) <= MAX_VECTOR_ALLOCATE, "Vector element size too large");
608 allocated = std::min(size, allocated + MAX_VECTOR_ALLOCATE / sizeof(typename V::value_type));
609 v.reserve(allocated);
610 while (v.size() < allocated) {
611 v.emplace_back();
612 formatter.Unser(s, v.back());
613 }
614 }
615 };
616};
617
618/**

Callers

nothing calls this directly

Calls 6

ReadCompactSizeFunction · 0.85
emplace_backMethod · 0.80
clearMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
UnserMethod · 0.45

Tested by

no test coverage detected