diff --git a/src/lib.rs b/src/lib.rs index 41f584c..674dd4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,6 +95,11 @@ pub fn load_image(image_base64: String) -> String { let mut state = STATE.lock().expect("Couldn't lock application state"); let image_base64: Vec<&str> = image_base64.split("base64,").collect(); + + if image_base64.len() < 2 { + return format!("Error: Badly-formatted base64: {}", image_base64.join("")); + } + let image_base64 = image_base64[1]; match base64::decode(image_base64) { @@ -109,13 +114,13 @@ pub fn load_image(image_base64: String) -> String { }, _ => { state.image = None; - "Couldn't load image".to_string() + "Error: Couldn't load image".to_string() } } }, _ => { state.image = None; - "Couldn't decode image".to_string() + "Error: Couldn't decode image".to_string() } } }