File size: 2,163 Bytes
1a94b98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226b7a0
1a94b98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
"""Build HuggingFace-compatible dataset from SEC-bench-Pro instances."""

import json
from pathlib import Path

import datasets

BASE_DIR = Path(__file__).resolve().parent.parent / "SEC-bench-Pro"
OUTPUT_DIR = Path(__file__).resolve().parent


def load_instances(engine: str) -> list[dict]:
    engine_dir = BASE_DIR / engine
    rows = []
    for meta_path in sorted(engine_dir.glob("*/meta.json")):
        with open(meta_path) as f:
            meta = json.load(f)

        instance_id = meta_path.parent.name

        fix_patches = []
        for fix in meta.get("fixes", []):
            patch_path = meta_path.parent / fix["path"]
            if patch_path.exists():
                fix_patches.append(patch_path.read_text())
            else:
                fix_patches.append("")

        row = {
            "instance_id": f"{engine}__{instance_id}",
            "project": engine,
            "bug_id": instance_id,
            "image_name": meta["image_name"],
            "work_dir": meta["work_dir"],
            "verification_binary": meta["verification_binary"],
            "command_options": meta.get("command_options", ""),
            "target_source_files": meta["target_source_files"],
            "target_subdir": meta["target_subdir"],
            "target_vulnerability_type": meta["target_vulnerability_type"],
            "error_type": meta["error_type"],
            "description": meta["description"],
            "vrp": str(meta.get("vrp") or ""),
            "fix_patches": fix_patches,
        }
        rows.append(row)
    return rows


def main():
    data_dir = OUTPUT_DIR / "data"
    data_dir.mkdir(exist_ok=True)

    v8_rows = load_instances("v8")
    sm_rows = load_instances("sm")
    all_rows = v8_rows + sm_rows

    datasets.Dataset.from_list(all_rows).to_parquet(data_dir / "all" / "test.parquet")
    datasets.Dataset.from_list(v8_rows).to_parquet(data_dir / "v8" / "test.parquet")
    datasets.Dataset.from_list(sm_rows).to_parquet(data_dir / "sm" / "test.parquet")

    print(f"Built dataset: all={len(all_rows)}, v8={len(v8_rows)}, sm={len(sm_rows)}")


if __name__ == "__main__":
    main()