mitex-rs / mitex

LaTeX support for Typst, powered by Rust and WASM. https://mitex-rs.github.io/mitex/
https://mitex-rs.github.io/mitex/tools/underleaf.html
Apache License 2.0
287 stars 10 forks source link

test: add afl fuzzer #113

Closed Enter-tainer closed 8 months ago

Enter-tainer commented 8 months ago

Usage

First prepare a bunch of tex input, I suggest the top 50 of oiwiki:

const test = require('./oiwiki-231222.json')
const fs = require('fs');
// write each test case to a file in a subdirectory

for (const [i, t] of test.entries()) {
  fs.writeFileSync(`./seed/${i}.txt`, t.text);
  if (i > 50) {
    break;
  }
}

Then build and fuzz

cargo afl build --bin fuzz-target-mitex
cargo afl fuzz -i local/seed -o local/fuzz-res ./target/debug/fuzz-target-mitex

To minimize test case, using afl-tmin

cargo afl tmin -i crash.tex -o minimized.tex ./target/debug/fuzz-target-mitex