Do not check for data oversize when unchecked.

This commit is contained in:
Stephen Chung 2020-06-15 22:04:14 +08:00
parent a417bdd8e3
commit fcb5059570
2 changed files with 37 additions and 31 deletions

View File

@ -29,24 +29,27 @@ fn pad<T: Variant + Clone>(engine: &Engine, args: &mut [&mut Dynamic]) -> FuncRe
let len = *args[1].downcast_ref::<INT>().unwrap(); let len = *args[1].downcast_ref::<INT>().unwrap();
// Check if array will be over max size limit // Check if array will be over max size limit
#[cfg(not(feature = "unchecked"))]
{
if engine.max_array_size > 0 && len > 0 && (len as usize) > engine.max_array_size { if engine.max_array_size > 0 && len > 0 && (len as usize) > engine.max_array_size {
Err(Box::new(EvalAltResult::ErrorDataTooLarge( return Err(Box::new(EvalAltResult::ErrorDataTooLarge(
"Size of array".to_string(), "Size of array".to_string(),
engine.max_array_size, engine.max_array_size,
len as usize, len as usize,
Position::none(), Position::none(),
))) )));
} else if len >= 0 { }
}
if len >= 0 {
let item = args[2].downcast_ref::<T>().unwrap().clone(); let item = args[2].downcast_ref::<T>().unwrap().clone();
let list = args[0].downcast_mut::<Array>().unwrap(); let list = args[0].downcast_mut::<Array>().unwrap();
while list.len() < len as usize { while list.len() < len as usize {
push(list, item.clone())?; push(list, item.clone())?;
} }
Ok(())
} else {
Ok(())
} }
Ok(())
} }
macro_rules! reg_op { macro_rules! reg_op {

View File

@ -222,14 +222,18 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
let len = *args[1].downcast_ref::< INT>().unwrap(); let len = *args[1].downcast_ref::< INT>().unwrap();
// Check if string will be over max size limit // Check if string will be over max size limit
#[cfg(not(feature = "unchecked"))]
{
if engine.max_string_size > 0 && len > 0 && (len as usize) > engine.max_string_size { if engine.max_string_size > 0 && len > 0 && (len as usize) > engine.max_string_size {
Err(Box::new(EvalAltResult::ErrorDataTooLarge( return Err(Box::new(EvalAltResult::ErrorDataTooLarge(
"Length of string".to_string(), "Length of string".to_string(),
engine.max_string_size, engine.max_string_size,
len as usize, len as usize,
Position::none(), Position::none(),
))) )));
} else { }
}
let ch = *args[2].downcast_ref::< char>().unwrap(); let ch = *args[2].downcast_ref::< char>().unwrap();
let s = args[0].downcast_mut::<ImmutableString>().unwrap(); let s = args[0].downcast_mut::<ImmutableString>().unwrap();
@ -248,7 +252,6 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
} else { } else {
Ok(()) Ok(())
} }
}
}, },
); );
lib.set_fn_3_mut( lib.set_fn_3_mut(