| #!/usr/bin/env python3 | |
| """Juliet Test Suite C/C++ 1.3 (NIST SARD #112, public domain) -> staged code_sample rows. | |
| Functions are split with tree-sitter (C or C++ grammar by extension). Label rule: function name contains 'bad' -> vulnerable, | |
| contains 'good' -> not vulnerable, anything else (main, helpers) is skipped. label_source=synthetic, confidence 1.0. | |
| pair_id groups every function of one test case (multi-file cases _NNa.c.._NNe.c are one case).""" | |
| import re, sys, zipfile, os | |
| sys.path.insert(0, os.path.dirname(__file__)); import codecommon as C | |
| ZIP = f"{C.ROOT}/raw/code/juliet_c/1.3/Juliet_Test_Suite_v1.3_for_C_Cpp.zip" | |
| LIC = "Public domain (NIST SARD Juliet 1.3, 17 USC 105)" | |
| w = C.StageWriter("juliet_c") | |
| z = zipfile.ZipFile(ZIP) | |
| for info in z.infolist(): | |
| p = info.filename | |
| m = re.match(r"C/testcases/(CWE(\d+)_[^/]+)/(?:s\d+/)?([^/]+)\.(c|cpp)$", p) | |
| if not m: continue | |
| cwedir, cwe, stem, ext = m.groups() | |
| case = re.sub(r"(_good\w*|_bad\w*)$", "", stem); case = re.sub(r"(_\d+)[a-z]$", r"\1", case) | |
| code = z.read(info).decode("latin-1") | |
| grammar = "c" if ext == "c" else "cpp" | |
| for name, s, e, fcode in C.split_functions(code, grammar): | |
| if not name: continue | |
| ln = name.lower() | |
| if "bad" in ln: vul = True | |
| elif "good" in ln: vul = False | |
| else: continue | |
| role = "vuln" if vul else "fix" | |
| w.add(language="c_cpp", language_detail=grammar, code=fcode, project="juliet_c_cpp_1.3", file_path=p[len("C/"):], | |
| func_name=name, start_line=s, end_line=e, is_vulnerable=vul, pair_id=C.sha256("juliet:" + case)[:32], pair_role=role, | |
| cwe_ids=[f"CWE-{int(cwe)}"], label_source="synthetic", label_confidence=1.0, | |
| origin={"dataset": "juliet_c_1.3", "original_id": f"{stem}.{ext}::{name}@L{s}", "original_label": "bad" if vul else "good"}, | |
| source_dataset="juliet_c", source_license=LIC, publishable_code=True, source_split=None, | |
| extra=None) | |
| w.close() | |
Xet Storage Details
- Size:
- 2 kB
- Xet hash:
- 167d2255244a51c076ccb6ecd7f871799a07533dd8ec2907ecbf2246396bddd3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.