diff --git a/.changes/ipc-fix.md b/.changes/ipc-fix.md new file mode 100644 index 000000000..089969472 --- /dev/null +++ b/.changes/ipc-fix.md @@ -0,0 +1,6 @@ +--- +"wry": patch +--- + +Fix IPC crash on wkwebview if receiving invalid types. + diff --git a/src/wkwebview/mod.rs b/src/wkwebview/mod.rs index cb41c7c6f..49d8f62e4 100644 --- a/src/wkwebview/mod.rs +++ b/src/wkwebview/mod.rs @@ -140,15 +140,17 @@ impl InnerWebView { if !function.is_null() { let function = &mut *(*function as *mut Box); let body: id = msg_send![msg, body]; - let utf8: *const c_char = msg_send![body, UTF8String]; - if let Ok(js) = CStr::from_ptr(utf8).to_str() { - (function)(js.to_string()); - } else { - log::warn!("WebView received invalid UTF8 string from IPC."); + let is_string: bool = msg_send![body, isKindOfClass: class!(NSString)]; + if is_string { + let utf8: *const c_char = msg_send![body, UTF8String]; + if let Ok(js) = CStr::from_ptr(utf8).to_str() { + (function)(js.to_string()); + return; + } } - } else { - log::warn!("WebView instance is dropped! This handler shouldn't be called."); } + + log::warn!("WebView received invalid IPC call."); } }