fix(core): two bugs blocking package operations on real devices (#1430)

* fix(core): two bugs blocking package operations on real devices

- adb.rs: replace debug_assert! in list_packages_sys with filter_map
  to avoid panicking on nonstandard package names from real devices.
- sync.rs: fix inverted guard in request_builder (is_some -> is_none)
  that was rejecting every valid package name instead of invalid ones.
This commit is contained in:
André Klein 2026-07-17 00:35:15 +03:00 committed by GitHub
commit 43d323332f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -44,7 +44,7 @@ use std::rc::Rc;
use std::os::windows::process::CommandExt;
use crate::utils::is_all_w_c;
use log::{error, info};
use log::{error, info, warn};
/// Convert ADB output bytes to a trimmed UTF-8 string.
/// Uses lossy conversion to prevent panics on non-UTF8 output from certain OEMs.
@ -366,11 +366,15 @@ impl PmCommand {
self.0.0.run().map(|pack_ls| {
pack_ls
.lines()
.map(|p_ln| {
.filter_map(|p_ln| {
debug_assert!(p_ln.starts_with(PACK_PREFIX));
let p = &p_ln[PACK_PREFIX.len()..];
debug_assert!(PackageId::new(p).is_some());
String::from(p)
if PackageId::new(p).is_some() {
Some(String::from(p))
} else {
warn!("skipping nonstandard package name: {p:?}");
None
}
})
.collect()
})

View file

@ -213,7 +213,7 @@ pub fn request_builder(commands: &[&str], package: &str, user: Option<User>) ->
// guarantee local to the sink instead of relying on each caller to sanitise.
// Fail closed: emit no command for a malformed name rather than an injectable
// device-shell string.
if PackageId::new(package).is_some() {
if PackageId::new(package).is_none() {
error!("request_builder: refusing invalid package name: {package:?}");
return Vec::new();
}