From 85d740b2954d80ff384b400b81a1187d3f7735b0 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Fri, 9 Aug 2024 21:56:19 +0530 Subject: [PATCH 1/3] feat: support bare executable artifacts --- lib/sources/artifact/format.rs | 8 ++++++++ lib/sources/artifact/mod.rs | 1 + lib/sources/artifact/util.rs | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/sources/artifact/format.rs b/lib/sources/artifact/format.rs index 2c7b789..4b8b24a 100644 --- a/lib/sources/artifact/format.rs +++ b/lib/sources/artifact/format.rs @@ -10,6 +10,8 @@ pub enum ArtifactFormat { Zip, Tar, TarGz, + Pe, + Elf, } impl ArtifactFormat { @@ -19,6 +21,8 @@ impl ArtifactFormat { Self::Zip => "zip", Self::Tar => "tar", Self::TarGz => "tar.gz", + Self::Pe => "exe", + Self::Elf => "", } } @@ -33,6 +37,8 @@ impl ArtifactFormat { { Some(Self::TarGz) } + [.., ext] if ext.eq_ignore_ascii_case("exe") => Some(Self::Pe), + [] => Some(Self::Elf), _ => None, } } @@ -53,6 +59,8 @@ impl FromStr for ArtifactFormat { "zip" => Ok(Self::Zip), "tar" => Ok(Self::Tar), "tar.gz" | "tgz" => Ok(Self::TarGz), + "exe" => Ok(Self::Pe), + "bin" => Ok(Self::Elf), _ => Err(format!("unknown artifact format '{l}'")), } } diff --git a/lib/sources/artifact/mod.rs b/lib/sources/artifact/mod.rs index 8533d72..60425f6 100644 --- a/lib/sources/artifact/mod.rs +++ b/lib/sources/artifact/mod.rs @@ -74,6 +74,7 @@ impl Artifact { let tar = decompress_gzip(&contents).await?; extract_tar_file(&tar, &file_name).await } + ArtifactFormat::Pe | ArtifactFormat::Elf => Ok(Some(contents.clone())), }; // Make sure we got back the file we need ... diff --git a/lib/sources/artifact/util.rs b/lib/sources/artifact/util.rs index 591922a..966bbfc 100644 --- a/lib/sources/artifact/util.rs +++ b/lib/sources/artifact/util.rs @@ -1,6 +1,6 @@ use std::path::Path; -const ALLOWED_EXTENSION_NAMES: [&str; 4] = ["zip", "tar", "gz", "tgz"]; +const ALLOWED_EXTENSION_NAMES: [&str; 6] = ["zip", "tar", "gz", "tgz", "exe", ""]; const ALLOWED_EXTENSION_COUNT: usize = 2; pub(super) fn split_filename_and_extensions(name: &str) -> (&str, Vec<&str>) { From 1e97559d1f93a891afa9e1942ee6314a0ae00e84 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Sat, 10 Aug 2024 11:05:19 +0530 Subject: [PATCH 2/3] feat(tests): include tests for bare executable matching --- lib/sources/artifact/format.rs | 17 +++++++++++++--- lib/sources/artifact/sorting.rs | 2 ++ lib/sources/artifact/util.rs | 35 ++++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/lib/sources/artifact/format.rs b/lib/sources/artifact/format.rs index 4b8b24a..9830b37 100644 --- a/lib/sources/artifact/format.rs +++ b/lib/sources/artifact/format.rs @@ -38,7 +38,7 @@ impl ArtifactFormat { Some(Self::TarGz) } [.., ext] if ext.eq_ignore_ascii_case("exe") => Some(Self::Pe), - [] => Some(Self::Elf), + [""] => Some(Self::Elf), _ => None, } } @@ -102,8 +102,8 @@ mod tests { #[test] fn format_from_extensions_invalid() { - assert_eq!(format_from_str("file-name"), None); - assert_eq!(format_from_str("some/file.exe"), None); + assert_eq!(format_from_str("file-name.txt"), None); + assert_eq!(format_from_str("some/file.mp4"), None); assert_eq!(format_from_str("really.long.file.name"), None); } @@ -125,6 +125,14 @@ mod tests { format_from_str("sentry-cli-linux-i686-2.32.1.tgz"), Some(ArtifactFormat::TarGz) ); + assert_eq!( + format_from_str("sentry-cli-Linux-x86_64"), + Some(ArtifactFormat::Elf) + ); + assert_eq!( + format_from_str("sentry-cli-Windows-x86_64.exe"), + Some(ArtifactFormat::Pe) + ); } #[test] @@ -138,5 +146,8 @@ mod tests { assert_eq!(format_from_str("file.tar.gz"), Some(ArtifactFormat::TarGz)); assert_eq!(format_from_str("file.TAR.GZ"), Some(ArtifactFormat::TarGz)); assert_eq!(format_from_str("file.Tar.Gz"), Some(ArtifactFormat::TarGz)); + assert_eq!(format_from_str("file.exe"), Some(ArtifactFormat::Pe)); + assert_eq!(format_from_str("file.EXE"), Some(ArtifactFormat::Pe)); + assert_eq!(format_from_str("file"), Some(ArtifactFormat::Elf)); } } diff --git a/lib/sources/artifact/sorting.rs b/lib/sources/artifact/sorting.rs index e9208c0..376a8da 100644 --- a/lib/sources/artifact/sorting.rs +++ b/lib/sources/artifact/sorting.rs @@ -161,6 +161,8 @@ mod tests { test_some_mentions("selene-light-0.27.1-linux.zip", "selene"); // Valid - but multiple words test_no_mentions("sentry-cli-linux-i686-2.32.1", "sentry-cli"); + test_no_mentions("sentry-cli-Windows-i686.exe", "sentry-cli"); + test_no_mentions("sentry-cli-Linux-i686", "sentry-cli"); test_no_mentions("selene-light-0.27.1-linux.zip", "selene-light"); } } diff --git a/lib/sources/artifact/util.rs b/lib/sources/artifact/util.rs index 966bbfc..e7445a8 100644 --- a/lib/sources/artifact/util.rs +++ b/lib/sources/artifact/util.rs @@ -9,25 +9,36 @@ pub(super) fn split_filename_and_extensions(name: &str) -> (&str, Vec<&str>) { // Reverse-pop extensions off the path until we reach the // base name - we will then need to reverse afterwards, too - while let Some(ext) = path.extension() { - let ext = ext.to_str().expect("input was str"); - let stem = path.file_stem().expect("had an extension"); + loop { + if let Some(ext) = path.extension() { + let ext = ext.to_str().expect("input was str"); + println!("Ext: {ext}"); + let stem = path.file_stem().expect("had an extension"); - if !ALLOWED_EXTENSION_NAMES - .iter() - .any(|e| e.eq_ignore_ascii_case(ext)) - { - break; - } + if !ALLOWED_EXTENSION_NAMES + .iter() + .any(|e| e.eq_ignore_ascii_case(ext)) + { + break; + } - exts.push(ext); - path = Path::new(stem); + exts.push(ext); + path = Path::new(stem); - if exts.len() >= ALLOWED_EXTENSION_COUNT { + if exts.len() >= ALLOWED_EXTENSION_COUNT { + break; + } + } else { + // Push an empty string if there are no more extensions in the path + exts.push(""); break; } } + if exts.len() > 1 && exts.contains(&"") { + exts.pop(); + } + exts.reverse(); let path = path.to_str().expect("input was str"); From fa9765a0ccd14480ea61749ed0d312667a3b86c9 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Sun, 11 Aug 2024 08:31:21 +0530 Subject: [PATCH 3/3] chore: regenerate lockfile --- Cargo.lock | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 605f388..9bb8c78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,9 +147,9 @@ dependencies = [ [[package]] name = "async-io" -version = "2.3.3" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6baa8f0178795da0e71bc42c9e5d13261aac7ee549853162e66a241ba17964" +checksum = "444b0228950ee6501b3568d3c93bf1176a1fdbc3b758dcd9475046d30f4dc7e8" dependencies = [ "async-lock", "cfg-if", @@ -161,7 +161,7 @@ dependencies = [ "rustix", "slab", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -183,9 +183,9 @@ checksum = "9338790e78aa95a416786ec8389546c4b6a1dfc3dc36071ed9518a9413a542eb" [[package]] name = "async-signal" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb3634b73397aa844481f814fad23bbf07fdb0eabec10f2eb95e58944b1ec32" +checksum = "637e00349800c0bdf8bfc21ebbc0b6524abea702b0da4168ac00d070d0c0b9f3" dependencies = [ "async-io", "async-lock", @@ -196,7 +196,7 @@ dependencies = [ "rustix", "signal-hook-registry", "slab", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -335,9 +335,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.8" +version = "1.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504bdec147f2cc13c8b57ed9401fd8a147cc66b67ad5cb241394244f2c947549" +checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292" dependencies = [ "jobserver", "libc", @@ -374,9 +374,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.14" +version = "4.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c937d4061031a6d0c8da4b9a4f98a172fc2976dfb1c19213a9cf7d0d3c837e36" +checksum = "11d8838454fda655dafd3accb2b6e2bea645b9e4078abe84a22ceb947235c5cc" dependencies = [ "clap_builder", "clap_derive", @@ -384,9 +384,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.14" +version = "4.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85379ba512b21a328adf887e85f7742d12e96eb31f3ef077df4ffc26b506ffed" +checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" dependencies = [ "anstream", "anstyle", @@ -466,9 +466,9 @@ checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" @@ -1530,9 +1530,9 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" [[package]] name = "polling" -version = "3.7.2" +version = "3.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3ed00ed3fbf728b5816498ecd316d1716eecaced9c0c8d2c5a6740ca214985b" +checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511" dependencies = [ "cfg-if", "concurrent-queue", @@ -1540,7 +1540,7 @@ dependencies = [ "pin-project-lite", "rustix", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]]