Before VarInt could have had a size of 7 byte without generating errors (max should be 5). >= 5 is because we start from 0 and i=5 is already in error. For example if byte of VarInt are [255 255 255 255 255 255 1], at penultimate iteration, i will be 5 (start at 0) so there aren't errors and at the last the break bypass the sec&0x80 check. Same for VarLong.