File: build_corpus.py

package info (click to toggle)
rust-json-event-parser 0.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 256 kB
  • sloc: python: 14; makefile: 2; sh: 1
file content (15 lines) | stat: -rw-r--r-- 477 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import hashlib
import random
from pathlib import Path

base = Path(__file__).parent.parent
target_dir = base / "fuzz" / "corpus" / "parse"
target_dir.mkdir(parents=True, exist_ok=True)
for f in base.rglob("*.json"):
    for _ in range(3):
        data = f.read_bytes()
        pos = random.randint(0, len(data))
        data = data[:pos] + b"\xff" + data[pos:]
        hash = hashlib.sha256()
        hash.update(data)
        (target_dir / hash.hexdigest()).write_bytes(data)