fix(input): validate escaped text against the actual command budget
The editor could clear 2048 quote characters although escaping exceeded the Native 4096-byte command budget. Measure the complete command before sending and retain oversized text. Core, Native and Browser use the 8192-byte UTF-8 carrier bound; independent queue budgets keep their own names. Static Browser values are compared with compiled Core, with no new WASM hot-path dependency. Real WebCrypto boundary probes, Native compilation and all 2521 Web tests pass.
This commit is contained in:
1 parent
ec34b77aec
commit
aa4e6ee45c
14 files changed
+65
-17
No files matched your search
@@ -5,6 +5,7 @@ use aes_gcm::{
|
||||
};
|
||||
use anyhow::{anyhow, ensure, Result};
|
||||
use base64::{engine::general_purpose::STANDARD, Engine};
|
||||
use piik_channel_core::input::INPUT_COMMAND_BYTES;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub(super) struct Cipher {
|
||||
@@ -25,7 +26,7 @@ impl Cipher {
|
||||
pub fn open(&mut self, data: &str, flow: Uuid) -> Result<Vec<u8>> {
|
||||
ensure!(data.len() <= 6144, "input_packet_too_large");
|
||||
let bytes = STANDARD.decode(data)?;
|
||||
ensure!((36..=4132).contains(&bytes.len()), "invalid_input_packet");
|
||||
ensure!((36..=36 + INPUT_COMMAND_BYTES).contains(&bytes.len()), "invalid_input_packet");
|
||||
let sequence = u64::from_be_bytes(bytes[..8].try_into()?);
|
||||
ensure!(sequence > self.received, "stale_input_packet");
|
||||
let plain = self
|
||||
|
||||
@@ -1464,7 +1464,7 @@ impl InputEvent {
|
||||
Some(Action::Held(Held::Button(button), down))
|
||||
}
|
||||
Self::Wheel { delta } if (-1200..=1200).contains(&delta) => Some(Action::Wheel(delta)),
|
||||
Self::Text { text } if text.len() <= 2048 && !text.contains('\0') => {
|
||||
Self::Text { text } if text.len() <= piik_channel_core::input::INPUT_TEXT_BYTES && !text.contains('\0') => {
|
||||
Some(Action::Text(text))
|
||||
}
|
||||
_ => None,
|
||||
|
||||
@@ -2521,7 +2521,7 @@ impl Driver {
|
||||
}
|
||||
}
|
||||
Lane::Input => {
|
||||
if !ready.open() || message.len() > 8192 {
|
||||
if !ready.open() || message.len() > piik_channel_core::input::INPUT_FRAME_BYTES {
|
||||
continue;
|
||||
}
|
||||
if let Ok(frame) = serde_json::from_slice(message.as_slice()) {
|
||||
|
||||
@@ -56,6 +56,8 @@ impl Estimate {
|
||||
}
|
||||
}
|
||||
|
||||
const INPUT_SEND_BUFFER_BYTES: usize = 8192;
|
||||
|
||||
// Finite SDK probing target when source demand is unknown, not a media limit.
|
||||
// An explicitly idle connection requests zero instead.
|
||||
const UNKNOWN_DEMAND_PROBE_BPS: u64 = 100_000_000;
|
||||
@@ -1768,7 +1770,7 @@ impl Channel {
|
||||
.context("channel not open")?;
|
||||
if input {
|
||||
ensure!(
|
||||
channel.buffered_amount() + bytes.len() <= 8192,
|
||||
channel.buffered_amount() + bytes.len() <= INPUT_SEND_BUFFER_BYTES,
|
||||
"input_channel_busy"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user