Fix empty attribute processing

This commit is contained in:
Wilson Lin 2020-01-04 17:50:39 +11:00
parent 94eec0d9af
commit 9695d6a990
2 changed files with 10 additions and 2 deletions

View File

@ -1,9 +1,9 @@
use afl::fuzz;
use hyperbuild::{hyperbuild, ErrorType};
use hyperbuild::hyperbuild;
fn main() {
fuzz!(|data: &[u8]| {
let mut mut_data: Vec<u8> = data.iter().map(|x| *x).collect();
hyperbuild(&mut mut_data);
let _ = hyperbuild(&mut mut_data);
});
}

View File

@ -236,6 +236,14 @@ pub fn process_attr_value(proc: &mut Processor, should_collapse_and_trim_ws: boo
};
// Ending delimiter quote (if any) has already been discarded at this point.
let minimum_value = proc.written_range(src_start);
// If minimum value is empty, return now before trying to read out of range later.
// (Reading starts at one character before end of minimum value.)
if minimum_value.empty() {
return Ok(ProcessedAttrValue {
delimiter: DelimiterType::Unquoted,
value: None,
});
};
// Stage 2: optimally minify attribute value using metrics.
let (optimal_delimiter, optimal_len) = metrics.get_optimal_delimiter_type(minimum_value.len());