From a31929ec081560a4ddafde3b51238d2d28423e33 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 18 Oct 2026 23:04:35 +0200 Subject: [PATCH] fix: bound M13 playlist snapshots within expanded IPC frames Verify: 256-playlist IPC regression failed at the former 64 KiB limit, then passed with the bounded 1 MiB limit. cargo test -p fader_master --test ipc_frames --quiet: 4 passed; config tests passed, including oversized media rejection; workspace clippy -D warnings and formatting passed. --- architecture.md | 4 ++++ config/src/profile.rs | 11 +++++++++++ config/tests/schema.rs | 17 +++++++++++++++++ fader_master/src/ipc.rs | 3 ++- fader_master/src/media_runtime/native.rs | 11 +++++++++++ fader_master/tests/ipc_frames.rs | 24 ++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 1 deletion(-) diff --git a/architecture.md b/architecture.md index 2cbff7d..0e6487b 100644 --- a/architecture.md +++ b/architecture.md @@ -203,6 +203,10 @@ edges through the bounded worker and exposes discovery, capabilities and state over IPC. The optional Media tab edits draft entries and controls; Save activates them. Learn/unbind is scoped to a selected control and surface. Media commands are not retried by the client after ambiguous transport failures. +IPC frames are limited to 1 MiB (oversized lengths are rejected before allocation). +Media configuration and discovery each have a 256 KiB serialized budget, so a +256-playlist response does not exceed the previous 64 KiB frame limit. Discovery +fails closed instead of publishing an incomplete set that could hide ambiguity. The MPRIS adapter uses pinned `dbus` 0.9.12 (MIT/Apache-2.0) and system libdbus-1; its upstream manifest does not declare an MSRV, so compatibility is diff --git a/config/src/profile.rs b/config/src/profile.rs index 7de1edc..ac25a29 100644 --- a/config/src/profile.rs +++ b/config/src/profile.rs @@ -577,6 +577,17 @@ impl Profile { fn validate_media(raw: &RawProfile) -> Result<(), ConfigError> { let invalid = |message: String| ConfigError::validation("media", message); + #[derive(Serialize)] + struct MediaSize<'a> { + media: &'a [media::Entry], + } + if toml::to_string(&MediaSize { media: &raw.media }) + .map_err(|e| invalid(e.to_string()))? + .len() + > 256 * 1024 + { + return Err(invalid("media configuration exceeds 256 KiB".into())); + } if raw.media.len() > 128 { return Err(invalid("at most 128 media entries".into())); } diff --git a/config/tests/schema.rs b/config/tests/schema.rs index 130bac0..8a6434b 100644 --- a/config/tests/schema.rs +++ b/config/tests/schema.rs @@ -6,6 +6,23 @@ const EXAMPLE: &str = include_str!("../../examples/profiles/desktop.toml"); const ARCH_PIPEWIRE: &str = include_str!("../../examples/profiles/arch-pipewire.toml"); const ARCHITECTURE: &str = include_str!("../../architecture.md"); +#[test] +fn media_configuration_has_a_bounded_ipc_budget() { + let mut source = EXAMPLE.to_owned(); + for n in 0..8 { + source.push_str(&format!("\n[[media]]\nid = 'entry-{n}'\nlabel = 'Player'\nselector = {{ field = 'identity', pattern = 'Player' }}\n")); + for c in 0..64 { + source.push_str(&format!("[[media.controls]]\nid = 'control-{c}'\naction = {{ kind = 'playlist', id = '/{}' }}\n", "x".repeat(1000))); + } + } + assert!( + Profile::parse(&source) + .unwrap_err() + .to_string() + .contains("256 KiB") + ); +} + #[test] fn media_entries_round_trip_and_validate_selectors_and_midi_collisions() { let extra = r#" diff --git a/fader_master/src/ipc.rs b/fader_master/src/ipc.rs index 2d24d74..2ae60f3 100644 --- a/fader_master/src/ipc.rs +++ b/fader_master/src/ipc.rs @@ -4,7 +4,8 @@ use serde::{Deserialize, Serialize, de::DeserializeOwned}; use thiserror::Error; pub const PROTOCOL_VERSION: u16 = 24; -pub const MAX_FRAME_BYTES: usize = 64 * 1024; +// Bounded playlist/discovery snapshots can legitimately exceed 64 KiB. +pub const MAX_FRAME_BYTES: usize = 1024 * 1024; /// Kind of mixer object addressed by a client. #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] diff --git a/fader_master/src/media_runtime/native.rs b/fader_master/src/media_runtime/native.rs index f4f1f5e..2ea8a7f 100644 --- a/fader_master/src/media_runtime/native.rs +++ b/fader_master/src/media_runtime/native.rs @@ -168,6 +168,17 @@ impl Adapter for DbusAdapter { }), } } + #[derive(serde::Serialize)] + struct DiscoverySize<'a> { + players: &'a [Player], + } + if toml::to_string(&DiscoverySize { players: &players }) + .map_err(|e| e.to_string())? + .len() + > 256 * 1024 + { + return Err("MPRIS discovery exceeds 256 KiB; refusing incomplete state".into()); + } Ok(players) } diff --git a/fader_master/tests/ipc_frames.rs b/fader_master/tests/ipc_frames.rs index 2a28f7b..2e3ec5f 100644 --- a/fader_master/tests/ipc_frames.rs +++ b/fader_master/tests/ipc_frames.rs @@ -32,6 +32,30 @@ fn bounded_toml_frame_round_trips_request_identity_and_revision() { ); } +#[test] +fn bounded_media_playlist_snapshot_round_trips_over_ipc() { + let snapshot = media::Snapshot { + available: true, + error: None, + players: vec![media::Player { + bus_name: "org.mpris.MediaPlayer2.fixture".into(), + playlists: (0..256) + .map(|n| media::Playlist { + id: format!("/playlist/{n}"), + name: "X".repeat(256), + }) + .collect(), + ..media::Player::default() + }], + }; + let mut bytes = Vec::new(); + write_frame(&mut bytes, &snapshot).unwrap(); + assert_eq!( + read_frame::(&mut Cursor::new(bytes)).unwrap(), + snapshot + ); +} + #[test] fn oversized_length_is_rejected_before_payload_allocation_or_read() { let length = u32::try_from(MAX_FRAME_BYTES + 1).unwrap().to_be_bytes();