Do not read whole webxdc file into memory

This seems not only wasteful but genuinly has the risk someone makes
their device useless by accidentally adding a huge file.

This also re-structures the checks a little: The if-conditions are
flattened out and cheap checks are done before more expensive ones.
This commit is contained in:
Floris Bruynooghe
2022-03-06 19:36:02 +01:00
parent 33ba8dabe0
commit b2fe723570
2 changed files with 55 additions and 39 deletions

View File

@@ -2,6 +2,7 @@
use std::collections::{HashMap, HashSet};
use std::future::Future;
use std::io::Cursor;
use std::pin::Pin;
use anyhow::{bail, Result};
@@ -1020,8 +1021,9 @@ impl MimeMessage {
if decoded_data.is_empty() {
return;
}
let reader = Cursor::new(decoded_data);
let msg_type = if context
.is_webxdc_file(filename, decoded_data)
.is_webxdc_file(filename, reader)
.await
.unwrap_or(false)
{