From b547466db7cbe68792bead541e7cd17c4e911429 Mon Sep 17 00:00:00 2001 From: kdletters Date: Sat, 20 Jun 2026 04:09:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E9=BD=90=E6=A1=8C=E9=9D=A2=E5=A3=B3?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=AF=BC=E5=87=BA=E7=A9=BA=E5=AD=97=E8=8A=82?= =?UTF-8?q?=E8=BE=B9=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 桌面壳图片导出解码后拒绝空字节内容 桌面壳 Rust 测试覆盖图片导出空内容拒绝 桌面壳配置检查反查图片导出字节边界 --- apps/desktop-shell/scripts/check-config.mjs | 11 +++++++++++ apps/desktop-shell/src-tauri/src/host_bridge/files.rs | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/desktop-shell/scripts/check-config.mjs b/apps/desktop-shell/scripts/check-config.mjs index cccc5087b..af15eb823 100644 --- a/apps/desktop-shell/scripts/check-config.mjs +++ b/apps/desktop-shell/scripts/check-config.mjs @@ -2294,6 +2294,17 @@ assertSameList( requiredRustHostModules, 'desktop shell Rust bridge modules', ); +const desktopExportImagePayloadBody = extractFunctionBody( + desktopHostBridgeFilesSource, + 'export_image_payload', +); +if ( + !desktopExportImagePayloadBody.includes( + 'bytes.is_empty() || bytes.len() > EXPORT_IMAGE_MAX_BYTES', + ) +) { + throw new Error('desktop shell image export must reject empty and oversized bytes'); +} assertSameList( extractNativeAppTauriInvokeCommands(nativeAppHostBridgeSource), ['HOST_BRIDGE_TAURI_COMMAND'], diff --git a/apps/desktop-shell/src-tauri/src/host_bridge/files.rs b/apps/desktop-shell/src-tauri/src/host_bridge/files.rs index 2d44cb81e..9dc06b73d 100644 --- a/apps/desktop-shell/src-tauri/src/host_bridge/files.rs +++ b/apps/desktop-shell/src-tauri/src/host_bridge/files.rs @@ -392,7 +392,7 @@ pub(crate) fn export_image_payload( "base64Data is invalid", ) })?; - if bytes.len() > EXPORT_IMAGE_MAX_BYTES { + if bytes.is_empty() || bytes.len() > EXPORT_IMAGE_MAX_BYTES { return Err(failed( request.id.clone(), "invalid_request", @@ -1272,6 +1272,15 @@ mod tests { "base64Data is invalid" ); + let mut empty = request("file.exportImage"); + empty.payload = Some(json!({ + "fileName": "分享卡.png", + "base64Data": "", + "mimeType": "image/png" + })); + let response = export_image_payload(&empty).expect_err("empty image"); + assert_eq!(response.error.expect("error").code, "invalid_request"); + let mut mismatched = request("file.exportImage"); mismatched.payload = Some(json!({ "fileName": "分享卡.png",