#!/usr/bin/env python3 """list_files.py : print the files the sweep probes, one per line, as / in byte order. * every file named *.h5 *.hdf5 *.he5 *.nc *.nc4 *.hdf *.h5f in each corpus, except netCDF classic / 64-bit-offset / CDF5 files (magic "CDF"): they are not HDF5, so neither side can read them and they say nothing; * plus, for cve_hdf5, every file in cvefiles/ and fuzzerfiles/ except .md/.c sources — the reproducers are mostly extension-less, and they are kept whatever their bytes look like (that is their point). """ import os import sys EXTS = (".h5", ".hdf5", ".he5", ".nc", ".nc4", ".hdf", ".h5f") def walk(top): for dirpath, dirnames, filenames in os.walk(top): dirnames[:] = [d for d in dirnames if d != ".git"] for fn in filenames: p = os.path.join(dirpath, fn) if os.path.isfile(p) and not os.path.islink(p): yield os.path.relpath(p, top) def main(root): out = set() for corpus in sorted(os.listdir(root)): top = os.path.join(root, corpus) if not os.path.isdir(top): continue for rel in walk(top): path = os.path.join(top, rel) if rel.lower().endswith(EXTS): with open(path, "rb") as fh: if fh.read(3) == b"CDF": continue out.add(f"{corpus}/{rel}") elif corpus == "cve_hdf5" and rel.split(os.sep)[0] in ("cvefiles", "fuzzerfiles") \ and not rel.endswith((".md", ".c")): out.add(f"{corpus}/{rel}") for f in sorted(out, key=lambda s: s.encode()): print(f) if __name__ == "__main__": main(sys.argv[1])