| 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 | /** |
nothing calls this directly
no test coverage detected