fuzzing: Enforce a maximum input length for peepmatic_compile target (#1985)

This avoids timeouts from large inputs, like
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23906
This commit is contained in:
Nick Fitzgerald
2020-07-07 07:03:14 -07:00
committed by GitHub
parent d6ae72abe6
commit 70cef0a433

View File

@@ -4,9 +4,16 @@ use peepmatic_runtime::PeepholeOptimizations;
use std::path::Path; use std::path::Path;
use std::str; use std::str;
// To avoid timeouts, don't deal with inputs larger than this.
const MAX_LEN: usize = 2048;
/// Attempt to interpret the given bytes as UTF-8 and then compile them as if /// Attempt to interpret the given bytes as UTF-8 and then compile them as if
/// they were source text of our DSL. /// they were source text of our DSL.
pub fn compile(data: &[u8]) { pub fn compile(data: &[u8]) {
if data.len() > MAX_LEN {
return;
}
let source = match str::from_utf8(data) { let source = match str::from_utf8(data) {
Err(_) => return, Err(_) => return,
Ok(s) => s, Ok(s) => s,