From 70cef0a433df9db0ee06faf042788d8a021a23af Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 7 Jul 2020 07:03:14 -0700 Subject: [PATCH] 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 --- cranelift/peepmatic/crates/fuzzing/src/compile.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cranelift/peepmatic/crates/fuzzing/src/compile.rs b/cranelift/peepmatic/crates/fuzzing/src/compile.rs index 8df8a685c5..ef635a6ba2 100644 --- a/cranelift/peepmatic/crates/fuzzing/src/compile.rs +++ b/cranelift/peepmatic/crates/fuzzing/src/compile.rs @@ -4,9 +4,16 @@ use peepmatic_runtime::PeepholeOptimizations; use std::path::Path; 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 /// they were source text of our DSL. pub fn compile(data: &[u8]) { + if data.len() > MAX_LEN { + return; + } + let source = match str::from_utf8(data) { Err(_) => return, Ok(s) => s,