[domistream] HTTP: MAX_APPS = 4095, derived from the XML element cap, on client and host alike

4096 apps of four elements each (App, AppTitle, ID, IsHdrSupported) plus the root need 16385 elements, one over MAX_XML_ELEMENTS, so the app cap could never be reached by a list as hosts write it and the host writer already stopped at 4095. Lowering the app cap to (MAX_XML_ELEMENTS - 1) / 4 = 4095 instead of raising the element cap keeps the XML parser's memory bound where it was and makes the two caps one number: the host's MAX_WRITTEN_APPS is now MAX_APPS, with a compile-time check that it fits.
This commit is contained in:
2026-12-04 12:57:10 +01:00
parent fa08511804
commit fd6333620d
2 changed files with 9 additions and 8 deletions
+4 -6
View File
@@ -46,12 +46,10 @@ pub struct HostInfo {
/// Maximum length of an error's `status_message`, in bytes. /// Maximum length of an error's `status_message`, in bytes.
pub const MAX_STATUS_MESSAGE_BYTES: usize = 256; 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 /// Most apps one `applist` answer carries: the client's [`crate::http::applist::MAX_APPS`], which is set so the
/// document stays within the client's [`crate::http::xml::MAX_XML_ELEMENTS`] (the root plus four elements per app). /// 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 = { pub const MAX_WRITTEN_APPS: usize = MAX_APPS;
let by_elements = (MAX_XML_ELEMENTS - 1) / 4; const _: () = assert!(1 + 4 * MAX_WRITTEN_APPS <= MAX_XML_ELEMENTS, "an applist at the cap must fit the XML cap");
if MAX_APPS < by_elements { MAX_APPS } else { by_elements }
};
/// The declaration every answer starts with. /// The declaration every answer starts with.
const DECLARATION: &str = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; const DECLARATION: &str = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
+5 -2
View File
@@ -1,12 +1,15 @@
//! `GET /applist` (`docs/PROTOCOL.md` 1.3). //! `GET /applist` (`docs/PROTOCOL.md` 1.3).
use super::xml::MAX_XML_ELEMENTS;
use crate::Result; use crate::Result;
use crate::util::{cap, malformed, parse_u32}; use crate::util::{cap, malformed, parse_u32};
/// Maximum size of an applist body, in bytes. /// Maximum size of an applist body, in bytes.
pub const MAX_APPLIST_BYTES: usize = 1024 * 1024; pub const MAX_APPLIST_BYTES: usize = 1024 * 1024;
/// Maximum number of apps accepted in one list. /// Maximum number of apps accepted in one list: as many as fit the XML element cap with the four elements a host
pub const MAX_APPS: usize = 4096; /// 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. /// Maximum length of an app title, in bytes.
pub const MAX_APP_TITLE_BYTES: usize = 512; pub const MAX_APP_TITLE_BYTES: usize = 512;