rnx: a packed result holds no spare capacity, so the listener sends a 16 MB result

This commit is contained in:
DeFiDude committed 2026-11-18 21:33:06 -07:00
1 parent 0e9bf3408a
commit 8ce5059a55
1 file changed
+25 -1
+25 -1
View File
@@ -154,7 +154,9 @@ impl CommandResult {
pub fn to_msgpack(&self) -> Vec<u8> {
let mut out = Vec::new();
rmpv::encode::write_value(&mut out, &self.to_value()).expect("encoding to a Vec");
out
// Deferred replies are admitted by allocation capacity; growth after a large
// output doubles it, and a 16 MB result would be refused.
out.into_boxed_slice().into_vec()
}
}
@@ -604,3 +606,25 @@ pub fn client_result(
};
(rendered, Some(response), code)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn packed_result_holds_no_spare_capacity() {
let result = CommandResult {
executed: true,
retcode: Some(0),
stdout: Some(vec![0x5a; 16_000_000]),
stderr: Some(Vec::new()),
stdout_len: Some(16_000_000),
stderr_len: Some(0),
started: 1.0,
concluded: Some(2.0),
};
let packed = result.to_msgpack();
assert!(packed.len() > 16_000_000);
assert_eq!(packed.capacity(), packed.len());
}
}