Skip to content

Commit 83c95e1

Browse files
committed
2squash: Increase received images size limit to 50 Mpx
+ Rename it to MAX_RCVD_IMAGE_PIXELS to make it clear that sending isn't affected. + Add a doc comment.
1 parent bc78492 commit 83c95e1

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/constants.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ pub(crate) const WORSE_AVATAR_BYTES: usize = 20_000; // this also fits to Outloo
223223
pub const BALANCED_IMAGE_SIZE: u32 = 1280;
224224
pub const WORSE_IMAGE_SIZE: u32 = 640;
225225

226-
// Limit displayed images ~8.3 megapixels (3840 × 2160)
227-
pub const MAX_IMAGE_PIXELS: u32 = 8294400;
226+
/// Limit for received images size. Bigger images become `Viewtype::File` to avoid excessive memory
227+
/// usage by UIs.
228+
pub const MAX_RCVD_IMAGE_PIXELS: u32 = 50_000_000;
228229

229230
// Key for the folder configuration version (see below).
230231
pub(crate) const DC_FOLDERS_CONFIGURED_KEY: &str = "folders_configured";

src/mimeparser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ impl MimeMessage {
13861386
{
13871387
match get_filemeta(decoded_data) {
13881388
// image size is known, not too big, keep msg_type:
1389-
Ok((width, height)) if width * height <= constants::MAX_IMAGE_PIXELS => {
1389+
Ok((width, height)) if width * height <= constants::MAX_RCVD_IMAGE_PIXELS => {
13901390
part.param.set_i64(Param::Width, width.into());
13911391
part.param.set_i64(Param::Height, height.into());
13921392
msg_type

src/mimeparser/mimeparser_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ async fn test_huge_image_becomes_file() -> Result<()> {
20042004
let t = TestContext::new_alice().await;
20052005
let msg_id = receive_imf(
20062006
&t,
2007-
include_bytes!("../../test-data/message/image_huge_36M.eml"),
2007+
include_bytes!("../../test-data/message/image_huge_64M.eml"),
20082008
false,
20092009
)
20102010
.await?
@@ -2017,8 +2017,8 @@ async fn test_huge_image_becomes_file() -> Result<()> {
20172017
assert_eq!(msg.get_filename().unwrap(), "huge_image.png");
20182018
assert_eq!(msg.get_filemime().unwrap(), "image/png");
20192019
// File has no width or height
2020-
assert_eq!(msg.param.get_int(Param::Width).unwrap_or_default(), 0);
2021-
assert_eq!(msg.param.get_int(Param::Height).unwrap_or_default(), 0);
2020+
assert!(msg.param.get_int(Param::Width).is_none());
2021+
assert!(msg.param.get_int(Param::Height).is_none());
20222022
Ok(())
20232023
}
20242024

test-data/message/image_huge_36M.eml renamed to test-data/message/image_huge_64M.eml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Content-Transfer-Encoding: base64
2424
Content-Disposition: attachment;
2525
filename="huge_image.png"
2626
27-
iVBORw0KGgoAAAANSUhEUgAAF3AAABdwCAIAAABsNhAUAAAAEElEQVR4nAEFAPr/AP////8AAAAFCeiupAAAAABJRU5ErkJggg==
27+
iVBORw0KGgoAAAANSUhEUgAAH0AAAB9ACAIAAACJkzqjAAAAEElEQVR4nAEFAPr/AP////8AAAAFCeiupAAAAABJRU5ErkJggg==
2828
--------------HUGE_IMAGE_BOUNDARY--

0 commit comments

Comments
 (0)