From 0d7325f8f6655c768ba82bcfed22a92bf8805b50 Mon Sep 17 00:00:00 2001 From: silverpill Date: Thu, 1 Sep 2022 12:21:25 +0000 Subject: [PATCH] Increase max download size --- src/activitypub/fetcher/fetchers.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/activitypub/fetcher/fetchers.rs b/src/activitypub/fetcher/fetchers.rs index 378bcf0..853e0c1 100644 --- a/src/activitypub/fetcher/fetchers.rs +++ b/src/activitypub/fetcher/fetchers.rs @@ -79,7 +79,7 @@ async fn send_request( Ok(data) } -const FILE_MAX_SIZE: usize = 1024 * 1024 * 10; +const FILE_MAX_SIZE: u64 = 1024 * 1024 * 20; pub async fn fetch_file( url: &str, @@ -87,8 +87,13 @@ pub async fn fetch_file( ) -> Result<(String, Option), FetchError> { let client = build_client()?; let response = client.get(url).send().await?; + if let Some(file_size) = response.content_length() { + if file_size > FILE_MAX_SIZE { + return Err(FetchError::OtherError("file is too large")); + }; + }; let file_data = response.bytes().await?; - if file_data.len() > FILE_MAX_SIZE { + if file_data.len() > FILE_MAX_SIZE as usize { return Err(FetchError::OtherError("file is too large")); }; let (file_name, media_type) = save_file(file_data.to_vec(), output_dir, None)?;