From 13449b195c55f1bfd2678df23bd45e1c99a329c8 Mon Sep 17 00:00:00 2001 From: Werner Kroneman Date: Sun, 3 Dec 2023 14:38:35 +0100 Subject: [PATCH] Fixed a crash when an avatar with a too-big size is being parsed. --- xmpp/src/pubsub/avatar.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/xmpp/src/pubsub/avatar.rs b/xmpp/src/pubsub/avatar.rs index d2c8aacd..4fbf0180 100644 --- a/xmpp/src/pubsub/avatar.rs +++ b/xmpp/src/pubsub/avatar.rs @@ -30,21 +30,26 @@ pub(crate) async fn handle_metadata_pubsub_event( for item in items { let payload = item.payload.clone().unwrap(); if payload.is("metadata", ns::AVATAR_METADATA) { - let metadata = Metadata::try_from(payload).unwrap(); - for info in metadata.infos { - let filename = format!("data/{}/{}", from, &*info.id.to_hex()); - let file_length = match fs::metadata(filename.clone()) { - Ok(metadata) => metadata.len(), - Err(_) => 0, - }; - // TODO: Also check the hash. - if info.bytes as u64 == file_length { - events.push(Event::AvatarRetrieved(from.clone(), filename)); - } else { - let iq = download_avatar(from); - let _ = agent.client.send_stanza(iq.into()).await; + + match Metadata::try_from(payload) { + Ok(metadata) => for info in metadata.infos { + let filename = format!("data/{}/{}", from, &*info.id.to_hex()); + let file_length = match fs::metadata(filename.clone()) { + Ok(metadata) => metadata.len(), + Err(_) => 0, + }; + // TODO: Also check the hash. + if info.bytes as u64 == file_length { + events.push(Event::AvatarRetrieved(from.clone(), filename)); + } else { + let iq = download_avatar(from); + let _ = agent.client.send_stanza(iq.into()).await; + } } + + Err(e) => error!("Error parsing avatar metadata: {}", e) } + } } events