diff --git a/crates/domistream/src/host/http/answer.rs b/crates/domistream/src/host/http/answer.rs index 0829b72..09f6d3d 100644 --- a/crates/domistream/src/host/http/answer.rs +++ b/crates/domistream/src/host/http/answer.rs @@ -46,12 +46,10 @@ pub struct HostInfo { /// Maximum length of an error's `status_message`, in bytes. pub const MAX_STATUS_MESSAGE_BYTES: usize = 256; -/// Most apps one `applist` answer carries: the client's [`crate::http::applist::MAX_APPS`], lowered so the -/// document stays within the client's [`crate::http::xml::MAX_XML_ELEMENTS`] (the root plus four elements per app). -pub const MAX_WRITTEN_APPS: usize = { - let by_elements = (MAX_XML_ELEMENTS - 1) / 4; - if MAX_APPS < by_elements { MAX_APPS } else { by_elements } -}; +/// Most apps one `applist` answer carries: the client's [`crate::http::applist::MAX_APPS`], which is set so the +/// document (the root plus four elements per app) stays within the client's [`crate::http::xml::MAX_XML_ELEMENTS`]. +pub const MAX_WRITTEN_APPS: usize = MAX_APPS; +const _: () = assert!(1 + 4 * MAX_WRITTEN_APPS <= MAX_XML_ELEMENTS, "an applist at the cap must fit the XML cap"); /// The declaration every answer starts with. const DECLARATION: &str = "\n"; diff --git a/crates/domistream/src/http/applist.rs b/crates/domistream/src/http/applist.rs index 0b6efc7..f6267d3 100644 --- a/crates/domistream/src/http/applist.rs +++ b/crates/domistream/src/http/applist.rs @@ -1,12 +1,15 @@ //! `GET /applist` (`docs/PROTOCOL.md` 1.3). +use super::xml::MAX_XML_ELEMENTS; use crate::Result; use crate::util::{cap, malformed, parse_u32}; /// Maximum size of an applist body, in bytes. pub const MAX_APPLIST_BYTES: usize = 1024 * 1024; -/// Maximum number of apps accepted in one list. -pub const MAX_APPS: usize = 4096; +/// Maximum number of apps accepted in one list: as many as fit the XML element cap with the four elements a host +/// writes per app (`App`, `AppTitle`, `ID`, `IsHdrSupported`) plus the root, so a full list is refused by this cap and +/// never by the XML parser first. +pub const MAX_APPS: usize = (MAX_XML_ELEMENTS - 1) / 4; /// Maximum length of an app title, in bytes. pub const MAX_APP_TITLE_BYTES: usize = 512;