In Core there is a max const for things that can be encoded and have their encode size represented by a compact integer (ie., VarInt). We are not, as far as I can see, enforcing this limit.
if (range_check && nSizeRet > MAX_SIZE) {
throw std::ios_base::failure("ReadCompactSize(): size too large");
}