diff --git a/.changes/fix-expect.md b/.changes/fix-expect.md new file mode 100644 index 000000000..4d7534559 --- /dev/null +++ b/.changes/fix-expect.md @@ -0,0 +1,6 @@ +--- +"wry": patch +--- + +Fix wkwebview crashed when received invalid UTF8 string from IPC. + diff --git a/src/wkwebview/mod.rs b/src/wkwebview/mod.rs index 68c9a4496..4003f030c 100644 --- a/src/wkwebview/mod.rs +++ b/src/wkwebview/mod.rs @@ -141,9 +141,11 @@ impl InnerWebView { let function = &mut *(*function as *mut Box); let body: id = msg_send![msg, body]; let utf8: *const c_char = msg_send![body, UTF8String]; - let js = CStr::from_ptr(utf8).to_str().expect("Invalid UTF8 string"); - - (function)(js.to_string()); + if let Ok(js) = CStr::from_ptr(utf8).to_str() { + (function)(js.to_string()); + } else { + log::warn!("WebView received invalid UTF8 string from IPC."); + } } else { log::warn!("WebView instance is dropped! This handler shouldn't be called."); }