Fix, online state, validate the data length (#16339)

* fix(client): reject truncated online status responses

Validate the bitmap length before indexing server-provided states. Return an error for short responses so they cannot panic or update cached online status.

Signed-off-by: fufesou <linlong1266@gmail.com>

* docs(client): illustrate online status bitmap sizing

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2026-09-25 00:35:47 +08:00
committed by GitHub
parent 341193290e
commit efec124c52
+9
View File
@@ -5369,6 +5369,15 @@ pub mod peer_online {
match msg_in.union {
Some(rendezvous_message::Union::OnlineResponse(online_response)) => {
let states = online_response.states;
// One bit per ID, rounded up to whole bytes:
// 0 IDs -> 0 bytes; 1..=8 -> 1; 9..=16 -> 2; 17..=24 -> 3.
let required_len = ids.len().div_ceil(u8::BITS as usize);
if states.len() < required_len {
bail!(
"Invalid online response: expected at least {required_len} state bytes, got {}",
states.len()
);
}
let mut onlines = Vec::new();
let mut offlines = Vec::new();
for i in 0..ids.len() {