630 | + while (allocated < size) {
631 | + // For DoS prevention, do not blindly allocate as much as the stream claims to contain.
632 | + // Instead, allocate in 5MiB batches, so that an attacker actually needs to provide
633 | + // X MiB of data to make us allocate X+5 Mib.
634 | + static_assert(sizeof(typename V::value_type) <= MAX_VECTOR_ALLOCATE, "Vector element size too large");
635 | + allocated = std::min(size, allocated + MAX_VECTOR_ALLOCATE / sizeof(typename V::value_type));
<strike>Now that the static assert suggested in #18021 (review) has been added, possibly worthwhile (or not) to calculate sizeof(typename V::value_type) once and cache it.</strike>
Noting that the result of sizeof is always nonzero, even if applied to an empty class type, so (normally) no risk of division by zero.
Unless I'm confused, sizeof(..) is determined at compile-time, so no reason to cache it.
Oops yes, static_assert requires a bool constexpr, otherwise a compile-time error is issued.