From 70df6e36ec3c76d0860174fd36a346f0c372bd8b Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 9 Apr 2024 13:09:12 -0300 Subject: [PATCH] fix(packager): crash when packaging empty file on macOS --- .changes/ignore-empty-files.md | 5 +++ bindings/packager/nodejs/index.js | 43 ++++++++++++++++++++++++++ crates/packager/src/package/app/mod.rs | 3 +- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .changes/ignore-empty-files.md diff --git a/.changes/ignore-empty-files.md b/.changes/ignore-empty-files.md new file mode 100644 index 00000000..c7e465d7 --- /dev/null +++ b/.changes/ignore-empty-files.md @@ -0,0 +1,5 @@ +--- +"cargo-packager": patch +--- + +Fixes a crash when packaging `.app` if an empty file is included in the bundle. diff --git a/bindings/packager/nodejs/index.js b/bindings/packager/nodejs/index.js index d34fa4a4..b1cc1ba1 100644 --- a/bindings/packager/nodejs/index.js +++ b/bindings/packager/nodejs/index.js @@ -237,6 +237,49 @@ switch (platform) { loadError = e } break + case 'riscv64': + if (isMusl()) { + localFileExisted = existsSync( + join(__dirname, 'packager.linux-riscv64-musl.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./packager.linux-riscv64-musl.node') + } else { + nativeBinding = require('@crabnebula/packager-linux-riscv64-musl') + } + } catch (e) { + loadError = e + } + } else { + localFileExisted = existsSync( + join(__dirname, 'packager.linux-riscv64-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./packager.linux-riscv64-gnu.node') + } else { + nativeBinding = require('@crabnebula/packager-linux-riscv64-gnu') + } + } catch (e) { + loadError = e + } + } + break + case 's390x': + localFileExisted = existsSync( + join(__dirname, 'packager.linux-s390x-gnu.node') + ) + try { + if (localFileExisted) { + nativeBinding = require('./packager.linux-s390x-gnu.node') + } else { + nativeBinding = require('@crabnebula/packager-linux-s390x-gnu') + } + } catch (e) { + loadError = e + } + break default: throw new Error(`Unsupported architecture on Linux: ${arch}`) } diff --git a/crates/packager/src/package/app/mod.rs b/crates/packager/src/package/app/mod.rs index 4d0f4ea0..746f1788 100644 --- a/crates/packager/src/package/app/mod.rs +++ b/crates/packager/src/package/app/mod.rs @@ -99,7 +99,8 @@ pub(crate) fn package(ctx: &Context) -> crate::Result> { } }; - if !metadata.is_file() { + // ignore folders and files that do not include at least the header size + if !metadata.is_file() || metadata.len() < 4 { continue; }