# Buggy code
def find_file(path, saltenv="base", **kwargs):
    """
    Look through the buckets cache file for a match.
    If the field is found, it is retrieved from S3 only if its cached version
    is missing, or if the MD5 does not match.
    """
    if "env" in kwargs:
        # "env" is not supported; Use "saltenv".
        kwargs.pop("env")

    fnd = {"bucket": None, "path": None}

    metadata = _init()
    if not metadata or saltenv not in metadata:
        return fnd

    env_files = _find_files(metadata[saltenv])

    if not _is_env_per_bucket():
        path = os.path.join(saltenv, path)

    # look for the files and check if they're ignored globally
    for bucket in env_files:
        for bucket_name, files in six.iteritems(bucket):
            if path in files and not fs.is_file_ignored(__opts__, path):
                fnd["bucket"] = bucket_name
                fnd["path"] = path
                break
        else:
            continue  # only executes if we didn't break
        break

    if not fnd["path"] or not fnd["bucket"]:
        return fnd

    cached_file_path = _get_cached_file_name(fnd["bucket"], saltenv, path)

    # jit load the file from S3 if it's not in the cache or it's old
    _get_file_from_s3(metadata, saltenv, fnd["bucket"], path, cached_file_path)

    return fnd


# Traceback (ValueError)
Exception occurred in runner state.orchestrate: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/client/mixins.py", line 382, in _low
data['return'] = self.functions[fun](*args, **kwargs)
File "/usr/lib/python2.7/site-packages/salt/runners/state.py", line 88, in orchestrate
orchestration_jid=orchestration_jid)
File "/usr/lib/python2.7/site-packages/salt/modules/state.py", line 1098, in sls
initial_pillar=_get_initial_pillar(opts))
File "/usr/lib/python2.7/site-packages/salt/state.py", line 3846, in __init__
BaseHighState.__init__(self, opts)
File "/usr/lib/python2.7/site-packages/salt/state.py", line 2721, in __init__
self.avail = self.__gather_avail()
File "/usr/lib/python2.7/site-packages/salt/state.py", line 2730, in __gather_avail
for saltenv in self._get_envs():
File "/usr/lib/python2.7/site-packages/salt/state.py", line 2791, in _get_envs
client_envs = self.client.envs()
File "/usr/lib/python2.7/site-packages/salt/fileclient.py", line 1331, in envs
return self.channel.send(load)
File "/usr/lib/python2.7/site-packages/salt/fileserver/__init__.py", line 892, in send
return self.fs.envs()
File "/usr/lib/python2.7/site-packages/salt/fileserver/__init__.py", line 488, in envs
ret.update(self.servers[fstr](**kwargs))
File "/usr/lib/python2.7/site-packages/salt/fileserver/s3fs.py", line 93, in envs
metadata = _init()
File "/usr/lib/python2.7/site-packages/salt/fileserver/s3fs.py", line 354, in _init
metadata = _read_buckets_cache_file(cache_file)
File "/usr/lib/python2.7/site-packages/salt/fileserver/s3fs.py", line 553, in _read_buckets_cache_file
data = pickle.load(fp_)
File "/usr/lib64/python2.7/pickle.py", line 1378, in load
return Unpickler(file).load()
File "/usr/lib64/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/lib64/python2.7/pickle.py", line 966, in load_string
raise ValueError, "insecure string pickle"
ValueError: insecure string pickle

# Fixed code
def find_file(path, saltenv="base", **kwargs):
    """
    Look through the buckets cache file for a match.
    If the field is found, it is retrieved from S3 only if its cached version
    is missing, or if the MD5 does not match.
    """
    if "env" in kwargs:
        # "env" is not supported; Use "saltenv".
        kwargs.pop("env")

    fnd = {"bucket": None, "path": None}

    metadata = _init()
    if not metadata or saltenv not in metadata:
        return fnd

    env_files = _find_files(metadata[saltenv])

    if not _is_env_per_bucket():
        path = os.path.join(saltenv, path)

    # look for the files and check if they're ignored globally
    for bucket in env_files:
        for bucket_name, files in bucket.items():
            if path in files and not fs.is_file_ignored(__opts__, path):
                fnd["bucket"] = bucket_name
                fnd["path"] = path
                break
        else:
            continue  # only executes if we didn't break
        break

    if not fnd["path"] or not fnd["bucket"]:
        return fnd

    cached_file_path = _get_cached_file_name(fnd["bucket"], saltenv, path)

    # jit load the file from S3 if it's not in the cache or it's old
    _get_file_from_s3(metadata, saltenv, fnd["bucket"], path, cached_file_path)

    return fnd