diff --git a/Source/WTF/wtf/Vector.h b/Source/WTF/wtf/Vector.h index ccd6c489f82d5..81139961d7221 100644 --- a/Source/WTF/wtf/Vector.h +++ b/Source/WTF/wtf/Vector.h @@ -208,8 +208,17 @@ struct VectorTypeOperations } }; +#if USE(BUN_JSC_ADDITIONS) +// m_capacity counts elements in 31 bits, next to the borrow bit. 310668@main halved the limit on the size in bytes +// instead, which halved the capacity of every Vector whose T is wider than a byte. This keeps the limit on the size +// in bytes from before that change and adds the limit on the count. +template +constexpr inline bool isValidCapacityForVector(size_t capacity) { return capacity <= std::min(std::numeric_limits::max() / sizeof(T), std::numeric_limits::max() >> 1); } +static_assert(isValidCapacityForVector(std::numeric_limits::max() >> 1) && !isValidCapacityForVector((std::numeric_limits::max() >> 1) + 1), "a valid capacity fits in the 31 bits of m_capacity"); +#else template constexpr inline bool isValidCapacityForVector(size_t capacity) { return capacity <= (std::numeric_limits::max() >> 1) / sizeof(T); } +#endif template struct CopyOrMoveToVectorResult; diff --git a/Source/WTF/wtf/text/StringImpl.h b/Source/WTF/wtf/text/StringImpl.h index cf4a02dac2ec3..6739dfd64ce50 100644 --- a/Source/WTF/wtf/text/StringImpl.h +++ b/Source/WTF/wtf/text/StringImpl.h @@ -1268,6 +1268,12 @@ inline constexpr bool StringImpl::isValidLength(size_t length) return length <= max; } +#if USE(BUN_JSC_ADDITIONS) +// The UTF-8 converters size a Vector by the length of their input. This fails to compile if a merge +// takes the halved limit of 310668@main for isValidCapacityForVector again. +static_assert(isValidCapacityForVector(StringImpl::MaxLength)); +#endif + template constexpr size_t StringImpl::tailOffset() { return roundUpToMultipleOf(offsetof(StringImpl, m_hashAndFlags) + sizeof(StringImpl::m_hashAndFlags));