base64_convert: bugs in base64_valid_length, flags not being used properly