| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
use std::path::{Path, PathBuf}; |
| 20 |
|
| 21 |
fn dir(rel: &str) -> PathBuf { |
| 22 |
Path::new(env!("CARGO_MANIFEST_DIR")).join(rel) |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
fn replay(dir: &Path) -> usize { |
| 30 |
let Ok(entries) = std::fs::read_dir(dir) else { |
| 31 |
return 0; |
| 32 |
}; |
| 33 |
|
| 34 |
let mut count = 0; |
| 35 |
for entry in entries { |
| 36 |
let path = entry.expect("readable dir entry").path(); |
| 37 |
if !path.is_file() { |
| 38 |
continue; |
| 39 |
} |
| 40 |
|
| 41 |
if path.extension().is_some_and(|e| e == "md") { |
| 42 |
continue; |
| 43 |
} |
| 44 |
let bytes = std::fs::read(&path).expect("readable input"); |
| 45 |
|
| 46 |
|
| 47 |
let outcome = std::panic::catch_unwind(|| shop_grid::oracle::check_bytes(&bytes)); |
| 48 |
assert!(outcome.is_ok(), "oracle failed on {}", path.display()); |
| 49 |
count += 1; |
| 50 |
} |
| 51 |
count |
| 52 |
} |
| 53 |
|
| 54 |
#[test] |
| 55 |
fn every_seed_holds_the_oracle() { |
| 56 |
let n = replay(&dir("fuzz/seeds/vt")); |
| 57 |
|
| 58 |
|
| 59 |
assert!( |
| 60 |
n >= 40, |
| 61 |
"expected the committed seed corpus, found {n} inputs" |
| 62 |
); |
| 63 |
} |
| 64 |
|
| 65 |
#[test] |
| 66 |
fn every_regression_holds_the_oracle() { |
| 67 |
|
| 68 |
|
| 69 |
replay(&dir("fuzz/regressions")); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
#[test] |
| 74 |
fn oracle_consumes_the_stream_it_is_given() { |
| 75 |
let input = b"\x63\x1dhello\x1b[31mworld\x1b[H\x1b[2J"; |
| 76 |
assert_eq!(shop_grid::oracle::check_bytes(input), input.len() - 2); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
#[test] |
| 87 |
fn unbounded_parser_growth_stays_capped() { |
| 88 |
|
| 89 |
|
| 90 |
let mut csi = b"\x4f\x17\x1b[".to_vec(); |
| 91 |
csi.extend(std::iter::repeat_n(b';', 4_000_000)); |
| 92 |
shop_grid::oracle::check_bytes(&csi); |
| 93 |
|
| 94 |
|
| 95 |
let over = shop_vt::MAX_STRING_BYTES * 2; |
| 96 |
for opener in [&b"\x4f\x17\x1b]"[..], &b"\x4f\x17\x1b_"[..]] { |
| 97 |
let mut body = opener.to_vec(); |
| 98 |
body.extend(std::iter::repeat_n(b'A', over)); |
| 99 |
shop_grid::oracle::check_bytes(&body); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
let mut big = b"\x4f\x17\x1b]0;".to_vec(); |
| 106 |
big.extend(std::iter::repeat_n(b'A', over)); |
| 107 |
big.extend_from_slice(b"\x07\x1b[0m"); |
| 108 |
shop_grid::oracle::check_bytes(&big); |
| 109 |
} |
| 110 |
|