From 1e65049d4842947ced6a807b93211542c46ca771 Mon Sep 17 00:00:00 2001 From: Jason Tsai Date: Thu, 16 May 2024 18:32:41 +0800 Subject: [PATCH] fix(macos): check IPC message body is null before deference it (#1267) --- .changes/fix-macos-ipc-empty-body-crash.md | 5 +++++ src/wkwebview/mod.rs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-macos-ipc-empty-body-crash.md diff --git a/.changes/fix-macos-ipc-empty-body-crash.md b/.changes/fix-macos-ipc-empty-body-crash.md new file mode 100644 index 000000000..268dbecd7 --- /dev/null +++ b/.changes/fix-macos-ipc-empty-body-crash.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +On macOS, fixed a crash when sending empty body by IPC. diff --git a/src/wkwebview/mod.rs b/src/wkwebview/mod.rs index a1ffb68f4..3b1b2312d 100644 --- a/src/wkwebview/mod.rs +++ b/src/wkwebview/mod.rs @@ -232,7 +232,9 @@ impl InnerWebView { if !body.is_null() { let length = msg_send![body, length]; let data_bytes: id = msg_send![body, bytes]; - sent_form_body = slice::from_raw_parts(data_bytes as *const u8, length).to_vec(); + if !data_bytes.is_null() { + sent_form_body = slice::from_raw_parts(data_bytes as *const u8, length).to_vec(); + } } else if !body_stream.is_null() { let _: () = msg_send![body_stream, open];