Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions crates/openlogi-assets/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,30 @@ pub fn safe_component_path(
label: label.to_owned(),
component: component.to_owned(),
};
// `Path::components` never yields separators on the platform that didn't
// produce them, so reject both kinds explicitly before consulting it.
if component.is_empty() || component.contains('/') || component.contains('\\') {
// Reject backslashes on every platform so a Windows-style separator can
// never sneak through on a Unix host (or vice versa).
if component.is_empty() || component.contains('\\') {
return Err(reject());
}
let mut parts = Path::new(component).components();
match (parts.next(), parts.next()) {
(Some(Component::Normal(_)), None) => Ok(base.join(component)),
_ => Err(reject()),
// Each `/`-separated component must be a normal, non-empty path segment.
// This allows the nested layouts the asset registry uses (e.g.
// `images/device/side_hero.png`) while still rejecting traversal
// (`..`, `.`, absolute paths, empty segments).
let mut normalized = PathBuf::new();
for part in component.split('/') {
if part.is_empty() {
return Err(reject());
}
let mut parsed = Path::new(part).components();
match (parsed.next(), parsed.next()) {
(Some(Component::Normal(name)), None) => normalized.push(name),
_ => return Err(reject()),
}
}
if normalized.as_os_str().is_empty() {
return Err(reject());
}
Ok(base.join(normalized))
}

/// Write `bytes` beside `dst` and atomically rename into place.
Expand All @@ -329,6 +343,9 @@ pub(crate) fn write_replace(dst: &Path, bytes: &[u8]) -> Result<(), AssetError>
path: dst.to_owned(),
source,
};
if let Some(parent) = dst.parent() {
std::fs::create_dir_all(parent).map_err(fail)?;
}
Comment on lines +346 to +348

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Nested downloads lack regression tests

Blocking. The repository requires each bug fix to have a regression test that fails without it. The new safe_component_path assertion only compares paths. Both existing write_replace tests use an existing parent directory, and every is_optional_asset test uses a flat name. Those tests still pass if parent creation or nested side-render selection is removed.

Add write_replace_creates_nested_parents and nested_side_render_is_optional, then record which reverted lines make them fail in the PR.

Rule Used: Severity: medium. Every bug fix ships a regression test that fails without the fix, and the PR states the counter-proof (the reverted line or the killed mutant). A test that passes with the fix reverted is not a regression test: ask for inputs where ... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

let mut file = AtomicWriteFile::open(dst).map_err(fail)?;
file.write_all(bytes).map_err(fail)?;
file.commit().map_err(fail)
Expand Down Expand Up @@ -391,6 +408,18 @@ mod tests {
assert_eq!(std::fs::read(&dst).expect("read back"), b"two");
}

#[test]
fn write_replace_creates_nested_parents() {
// Regression: nested asset paths (e.g. `images/device/side_hero.png`)
// must have their parent directories created on write.
let dir = tempfile::tempdir().expect("create temp dir");
let dst = dir.path().join("images/device/side_hero.png");

write_replace(&dst, b"payload").expect("nested write");

assert_eq!(std::fs::read(&dst).expect("read back"), b"payload");
}

#[cfg(unix)]
#[test]
fn write_replace_replaces_a_planted_symlink_instead_of_following_it() {
Expand All @@ -416,6 +445,10 @@ mod tests {
safe_component_path(Path::new("/cache"), "front_core.png", "asset").ok(),
Some(Path::new("/cache").join("front_core.png"))
);
assert_eq!(
safe_component_path(Path::new("/cache"), "images/device/side_hero.png", "asset").ok(),
Some(Path::new("/cache").join("images/device/side_hero.png"))
);
assert_eq!(
safe_component_path(Path::new("/cache"), "mx_master_4", "depot").ok(),
Some(Path::new("/cache").join("mx_master_4"))
Expand All @@ -429,7 +462,9 @@ mod tests {
".",
"..",
"../LaunchAgents/x",
"nested/file.png",
"nested/../file.png",
"nested/./file.png",
"nested//file.png",
"nested\\file.png",
"/etc/passwd",
] {
Expand Down
21 changes: 20 additions & 1 deletion crates/openlogi-cli/src/cmd/assets/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ use openlogi_assets::{AssetRegistry, FRONT_RENDER_FILES, FetchOutcome, METADATA_
///
/// (`back_*` renders stay remote until an easyswitch view needs them.)
fn is_optional_asset(name: &str) -> bool {
if name == "side_core.png" || name == "side.png" {
// A side render may live at a nested path in newer depots
// (`images/device/side_hero.png`); match on the basename so those are
// fetched too.
let basename = name.rsplit('/').next().unwrap_or(name);
let is_png = std::path::Path::new(basename)
.extension()
.is_some_and(|ext| ext.eq_ignore_ascii_case("png"));
if basename == "side_core.png"
|| basename == "side.png"
|| (basename.starts_with("side_") && is_png)
{
return true;
}
if (name.starts_with("core_metadata_") || name.starts_with("metadata_"))
Expand Down Expand Up @@ -161,6 +171,15 @@ mod is_optional_asset_tests {
assert!(is_optional_asset("side.png"));
}

#[test]
fn nested_side_render_is_optional() {
// Regression: depots that store the side render under a nested path
// (e.g. `images/device/side_hero.png`) must still be treated as
// optional side renders, otherwise they are never fetched.
assert!(is_optional_asset("images/device/side_hero.png"));
assert!(is_optional_asset("images/device/side_riot.png"));
}

#[test]
fn colour_variant_names_are_optional() {
assert!(is_optional_asset("front_ext1.png"));
Expand Down
3 changes: 2 additions & 1 deletion crates/openlogi-core/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ pub use defaults::{
pub use effect::{Effect, MediaKey, MouseButton, NativeAction, Script, Shortcut};
pub use g_keys::{GKey, GKeyProfile, GKeySlot, ModeKey};
pub use gaming::{
G502_LIGHTSPEED, G903_LIGHTSPEED, GamingButtons, GamingLayout, STANDARD_BUTTONS, Slot,
G502_HERO, G502_LIGHTSPEED, G903_LIGHTSPEED, GamingButtons, GamingLayout, STANDARD_BUTTONS,
Slot,
};
pub use gesture::GestureDirection;
pub use key_combo::{KeyCombo, KeyComboParseError, KeyboardUsage, KeyboardUsageError};
Expand Down
39 changes: 38 additions & 1 deletion crates/openlogi-core/src/binding/gaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@ pub const G903_LIGHTSPEED: GamingLayout = GamingLayout {
stock_dpi_presets: &[400, 800, 1600, 3200, 6400],
};

/// G502 HERO (wired, model key `0c08b`).
///
/// Wired USB variant of the G502 family. Its `0x8110` slot table was measured
/// on real hardware (`openlogi diag mouse-buttons`): 11 slots with the identity
/// host-mode mapping `01 02 03 04 05 06 07 08 09 0a 0b`, the same shape as the
/// G502 LIGHTSPEED, and the same physical button layout, so the slot-to-button
/// mapping mirrors [`G502_LIGHTSPEED`]. Stock DPI presets were not measured on
/// this hardware and stay empty; the DPI cycle falls back to user-configured
/// presets.
pub const G502_HERO: GamingLayout = GamingLayout {
model_keys: &["0c08b"],
slots: &[
Slot::native(ButtonId::LeftClick),
Slot::native(ButtonId::RightClick),
Slot::native(ButtonId::MiddleClick),
Slot::native(ButtonId::Back),
Slot::native(ButtonId::Forward),
Slot::stock(ButtonId::G6, Action::DpiShift),
Slot::stock(ButtonId::G7, Action::PreviousDpiPreset),
Slot::stock(ButtonId::G8, Action::NextDpiPreset),
// G9 cycles the onboard profiles, which has no host equivalent.
Slot::stock(ButtonId::G9, Action::None),
Slot::silent(ButtonId::WheelTiltRight),
Slot::silent(ButtonId::WheelTiltLeft),
],
stock_dpi_presets: &[],
Comment thread
MikiDevAHM marked this conversation as resolved.
Resolved
};

/// A gaming mouse whose layout nobody has dumped. Its first five slots are
/// the standard HID buttons, which the OS input hook remaps without host
/// mode. G6 and up differ per model and are not guessed.
Expand All @@ -129,7 +157,7 @@ pub const STANDARD_BUTTONS: GamingLayout = GamingLayout {
stock_dpi_presets: &[],
};

const LAYOUTS: &[&GamingLayout] = &[&G502_LIGHTSPEED, &G903_LIGHTSPEED];
const LAYOUTS: &[&GamingLayout] = &[&G502_LIGHTSPEED, &G903_LIGHTSPEED, &G502_HERO];

/// Whether a device is a G-series mouse, and which buttons it offers. The
/// agent, the tabs and the Buttons panel all ask this one verdict.
Expand Down Expand Up @@ -341,6 +369,15 @@ mod tests {
assert!(!layout.remappable().any(|b| layout.needs_host_mode(b)));
}

#[test]
fn g502_hero_resolves_and_has_eleven_slots() {
assert_eq!(GamingLayout::for_model_key("0c08b"), Some(&G502_HERO));
assert_eq!(G502_HERO.slots.len(), 11);
assert_eq!(G502_HERO.slot_of(ButtonId::G6), Some(5));
assert!(G502_HERO.needs_host_mode(ButtonId::G6));
assert!(!G502_HERO.needs_host_mode(ButtonId::Back));
}

#[test]
fn unknown_models_have_no_layout() {
assert_eq!(GamingLayout::for_model_key("04099"), None);
Expand Down
16 changes: 9 additions & 7 deletions crates/openlogi-desktop/src/services/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ fn main_view(path: PathBuf, side: Option<&SideView>, front: Option<&PathBuf>) ->

fn resolve_side_view(
dir: &Path,
depot: &str,
entry: &DeviceEntry,
manifest: Option<&DepotManifest>,
extended_model_id: u8,
Expand All @@ -177,12 +178,12 @@ fn resolve_side_view(
metadata
.image(SIDE_VIEW_KEY)
.filter(|image| !image.assignments.is_empty())?;
let variant = manifest.and_then(|m| {
entry.model_id_candidates().find_map(|base| {
m.resource_for_variant(base, extended_model_id, SIDE_VIEW_KEY)
.map(str::to_string)
})
});
// Resolve the side render through the same candidate bases the front
// render uses (which include the depot name), so depots that key their
// manifest variants on the depot name rather than a registry model id
// still resolve.
let variant = manifest
.and_then(|m| find_variant_in_manifest(m, entry, depot, extended_model_id, side_image_for));
Comment on lines +185 to +186

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Side-view fix lacks regression coverage. Blocking. Add a test such as depot_named_nested_side_view_resolves that calls AssetResolver::resolve with a depot-named manifest entry, a nested side render, and no side.png. Assert the returned side_view path and dimensions.

I checked the existing tests: the depot-named base render uses side.png, which the old fallback already finds; the drawable colour test never checks side_view; and the WebP test uses a registry model ID. None catches removal of this depot-name lookup. The repository requires every bug fix to include a test that fails without it. Record that counter-proof in the PR too.

Rule Used: Severity: medium. Every bug fix ships a regression test that fails without the fix, and the PR states the counter-proof (the reverted line or the killed mutant). A test that passes with the fix reverted is not a regression test: ask for inputs where ... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

let (image_path, (png_width, png_height)) = variant
.into_iter()
.chain(["side.png".to_string()])
Expand Down Expand Up @@ -459,7 +460,8 @@ impl AssetResolver {
debug!(depot, root = %root.display(), "depot ships no hotspot metadata — rendering image without hotspots");
Metadata::default()
};
let side_view = resolve_side_view(&dir, entry, manifest.as_ref(), ext, &metadata);
let side_view =
resolve_side_view(&dir, depot, entry, manifest.as_ref(), ext, &metadata);
let image_path = main_view(image_path, side_view.as_ref(), hero_image_path.as_ref());
let (png_width, png_height) = match read_image_dimensions(&image_path) {
Ok(dims) => dims,
Expand Down
7 changes: 7 additions & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,13 @@ that mouse has no adjustable DPI; DPI presets saved for it are ignored. This
makes the MX Ergo's precision button work with its default binding. On a mouse
with adjustable DPI, `CycleDpiPresets` keeps cycling the DPI presets.

G502 HERO (wired, `046d:c08b`) ships no stock DPI presets in OpenLogi, so
its `PreviousDpiPreset` / `NextDpiPreset` buttons do nothing until you save at
least two DPI presets in `config.toml` (or use `CycleDpiPresets`'s default).
Its remappable buttons (wheel click, back, forward, G6–G9, both wheel tilts)
work in host mode; primary clicks are not reassignable. The G6 (sniper) button
is DPI Shift by default.

A mouse with a DPI LED (HID++ `0x1300`), such as the MX Ergo, shows the mode
on that LED, as in Logi Options+. The LED lights when precision mode starts
and goes dark when it ends. OpenLogi takes control of the LED from the
Expand Down
Loading