def extract_zip(archive_path, dest):
    with zipfile.ZipFile(archive_path) as z:
        validate_filenames(z.namelist())
        z.extractall(dest)
        # Set file permissions. Tar does this by default, but with zip we need
        # to do it ourselves.
        for info in z.filelist:
            if not info.filename.endswith('/'):
                # This is how to get file permissions out of a zip archive,
                # according to http://stackoverflow.com/q/434641/823869 and
                # http://bugs.python.org/file34873/issue15795_cleaned.patch.
                mode = (info.external_attr >> 16) & 0o777
                # Don't copy the whole mode, just set the executable bit. Two
                # reasons for this. 1) This is all going to end up in a git
                # tree, which only records the executable bit anyway. 2) Zip's
                # support for Unix file modes is nonstandard, so the mode field
                # is often zero and could be garbage. Mistakenly setting a file
                # executable isn't a big deal, but e.g. removing read
                # permissions would cause an error.
                if mode & stat.S_IXUSR:
                    os.chmod(os.path.join(dest, info.filename), 0o755)