Fixed a crash when an avatar with a too-big size is being parsed.
This commit is contained in:
parent
4daeaf362f
commit
13449b195c
1 changed files with 18 additions and 13 deletions
|
@ -30,21 +30,26 @@ pub(crate) async fn handle_metadata_pubsub_event(
|
||||||
for item in items {
|
for item in items {
|
||||||
let payload = item.payload.clone().unwrap();
|
let payload = item.payload.clone().unwrap();
|
||||||
if payload.is("metadata", ns::AVATAR_METADATA) {
|
if payload.is("metadata", ns::AVATAR_METADATA) {
|
||||||
let metadata = Metadata::try_from(payload).unwrap();
|
|
||||||
for info in metadata.infos {
|
match Metadata::try_from(payload) {
|
||||||
let filename = format!("data/{}/{}", from, &*info.id.to_hex());
|
Ok(metadata) => for info in metadata.infos {
|
||||||
let file_length = match fs::metadata(filename.clone()) {
|
let filename = format!("data/{}/{}", from, &*info.id.to_hex());
|
||||||
Ok(metadata) => metadata.len(),
|
let file_length = match fs::metadata(filename.clone()) {
|
||||||
Err(_) => 0,
|
Ok(metadata) => metadata.len(),
|
||||||
};
|
Err(_) => 0,
|
||||||
// TODO: Also check the hash.
|
};
|
||||||
if info.bytes as u64 == file_length {
|
// TODO: Also check the hash.
|
||||||
events.push(Event::AvatarRetrieved(from.clone(), filename));
|
if info.bytes as u64 == file_length {
|
||||||
} else {
|
events.push(Event::AvatarRetrieved(from.clone(), filename));
|
||||||
let iq = download_avatar(from);
|
} else {
|
||||||
let _ = agent.client.send_stanza(iq.into()).await;
|
let iq = download_avatar(from);
|
||||||
|
let _ = agent.client.send_stanza(iq.into()).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Err(e) => error!("Error parsing avatar metadata: {}", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
events
|
events
|
||||||
|
|
Loading…
Reference in a new issue