| #!/usr/bin/env python3 | |
| """DiverseVul (no license -> RESTRICTED: code is never stored or published; only hashes, IDs and labels). | |
| target=1 -> vulnerable (label_source=diversevul_commit, 0.60); target=0 -> not vulnerable (0.50). | |
| Repo URLs / CVEs come from diversevul_metadata.json (commit -> repo_url, CWE, CVE).""" | |
| import sys, os, json | |
| sys.path.insert(0, os.path.dirname(__file__)); import codecommon as C | |
| D = f"{C.ROOT}/raw/code/diversevul/2023"; LIC = "RESTRICTED: DiverseVul has no license (IDs/hashes/labels only; rebuild locally)" | |
| def work(wi, args): | |
| start, lines, meta = args | |
| w = C.StageWriter("diversevul", worker=wi, clear=False) | |
| for j, line in enumerate(lines): | |
| r = json.loads(line); vul = str(r["target"]) == "1"; m = meta.get(r["commit_id"], {}) | |
| w.add(language="c_cpp", language_detail="c_or_cpp", code=r["func"], project=r.get("project"), commit_sha=r.get("commit_id"), | |
| repo_url=m.get("repo_url"), is_vulnerable=vul, pair_role="vuln" if vul else None, | |
| cve_ids=C.cves(m.get("CVE")), cwe_ids=C.cwes(r.get("cwe")) or (C.cwes(m.get("CWE")) if vul else []), | |
| label_source="diversevul_commit", label_confidence=C.confidence("diversevul_commit", "vuln" if vul else None), | |
| origin={"dataset": "diversevul_20230702", "original_id": f"line:{start + j}|hash:{r.get('hash')}", "original_label": str(r["target"])}, | |
| source_dataset="diversevul", source_license=LIC, publishable_code=False, source_split=None, extra=None) | |
| return w.close() | |
| if __name__ == "__main__": | |
| meta = {} | |
| for l in open(f"{D}/diversevul_metadata.json"): | |
| if l.strip(): x = json.loads(l); meta[x["commit_id"]] = x | |
| L = open(f"{D}/diversevul_20230702.json").read().splitlines() | |
| tasks = [] | |
| for k in range(0, len(L), 25000): | |
| sub = L[k:k + 25000]; cm = {} | |
| for l in sub: | |
| cid = json.loads(l)["commit_id"] | |
| if cid in meta: cm[cid] = meta[cid] | |
| tasks.append((k, sub, cm)) | |
| del L | |
| C.run_pool("diversevul", tasks, work) | |
Xet Storage Details
- Size:
- 2.05 kB
- Xet hash:
- 96eb745768cbf56c7d22e4511d9f2fbaf5196e47698ad19670ab8966aa6b9386
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.