fix(servo): bound live protocol metadata

This commit is contained in:
2026-07-09 23:32:17 -04:00
parent a6e3aeaf46
commit 83badaea81
13 changed files with 482 additions and 68 deletions
+25 -2
View File
@@ -10,11 +10,10 @@ use super::{
ServoLiveError, ServoLiveFrame, ServoLivePermissionGrant,
wire::{
LiveRequest, LiveResponse, LiveSurfaceHandle, MAX_FRAME_BYTE_COUNT, MAX_FRAME_DIMENSION,
MAX_RESPONSE_HEADER_BYTES,
},
};
const MAX_RESPONSE_HEADER_BYTES: usize = 256 * 1024;
pub(super) struct ServoLiveIpc {
requests: Option<Sender<IpcRequest>>,
thread: Option<JoinHandle<()>>,
@@ -257,6 +256,30 @@ mod tests {
));
}
#[test]
fn reply_accepts_the_exact_header_limit() -> Result<(), ServoLiveError> {
let mut header = br#"{"protocol_version":3,"error":null,"frame":null}"#.to_vec();
header.resize(MAX_RESPONSE_HEADER_BYTES - 1, b' ');
header.push(b'\n');
let reply = read_reply(&mut Cursor::new(header))?;
assert_eq!(reply.protocol_version, Some(3));
Ok(())
}
#[test]
fn reply_rejects_one_byte_over_the_header_limit() {
let mut header = br#"{"protocol_version":3,"error":null,"frame":null}"#.to_vec();
header.resize(MAX_RESPONSE_HEADER_BYTES, b' ');
header.push(b'\n');
assert!(matches!(
read_reply(&mut Cursor::new(header)),
Err(ServoLiveError::ResponseHeaderTooLarge { limit: MAX_RESPONSE_HEADER_BYTES })
));
}
#[test]
fn reply_parses_permission_consumption_without_a_frame() -> Result<(), ServoLiveError> {
let profile_id = ely_domain::ProfileId::new();
@@ -5,6 +5,7 @@ use super::ServoLiveSitePermission;
pub(super) const LIVE_PROTOCOL_VERSION: u32 = 3;
pub(super) const MAX_FRAME_DIMENSION: u32 = 16_384;
pub(super) const MAX_FRAME_BYTE_COUNT: usize = 256 * 1024 * 1024;
pub(super) const MAX_RESPONSE_HEADER_BYTES: usize = 256 * 1024;
#[derive(Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]