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.
This commit is contained in:
parent
6ee082673b
commit
a31929ec08
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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#"
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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::<media::Snapshot>(&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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue