From aaf881b31e286a3706d9cddc5f22c1f745a442df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Talbot?= <108630700+fetchfern@users.noreply.github.com> Date: Sun, 15 Nov 2026 12:50:16 -0500 Subject: [PATCH 1/2] chore(app): tweak limits to match backend --- packages/app-lib/src/api/instance/shared/content.rs | 7 ++----- packages/app-lib/src/api/instance/shared/mod.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/app-lib/src/api/instance/shared/content.rs b/packages/app-lib/src/api/instance/shared/content.rs index 1d2e15dea52..d4ee1facf08 100644 --- a/packages/app-lib/src/api/instance/shared/content.rs +++ b/packages/app-lib/src/api/instance/shared/content.rs @@ -95,23 +95,20 @@ fn newest_config_files<'a>( fn ensure_config_limits( external_files: &[ExternalFileResponse], ) -> crate::Result<()> { - let mut count = 0; let mut size = 0_u64; for file in external_files .iter() .filter(|file| file.file_type == CONFIG_FILE_TYPE) { - count += 1; size = size.saturating_add( file.file_size .and_then(|size| u64::try_from(size).ok()) .unwrap_or(u64::MAX), ); } - if count > MAX_SHARED_FILES || size > MAX_SHARED_FILES_TOTAL_SIZE { + if size > MAX_SHARED_FILES_TOTAL_SIZE { bail!(crate::ErrorKind::InputError( - "shared instance files exceed the size or file count limit" - .to_string(), + "shared instance files exceed the size limit".to_string(), )); } Ok(()) diff --git a/packages/app-lib/src/api/instance/shared/mod.rs b/packages/app-lib/src/api/instance/shared/mod.rs index 681562781dd..76501a1bfd0 100644 --- a/packages/app-lib/src/api/instance/shared/mod.rs +++ b/packages/app-lib/src/api/instance/shared/mod.rs @@ -37,8 +37,14 @@ pub(crate) const CONFIG_BUNDLE_FILE_TYPE: &str = "configs"; pub(crate) const CONFIG_FILE_TYPE: &str = "config"; pub(crate) const CONFIG_SYNC_ENABLED: bool = true; pub(crate) const CONFIG_DIRECTORY: &str = "config"; -pub(crate) const MAX_SHARED_FILES: usize = 4096; -pub(crate) const MAX_SHARED_FILES_TOTAL_SIZE: u64 = 500 * 1024 * 1024; +/// Number of files an owner can select to share in a version. The backend has +/// no file count limit, this keeps the version creation body under its size +/// limit. +pub(crate) const MAX_SHARED_FILES: usize = 16384; +/// Largest total size of a version's shared files, matching the backend's +/// per-version external file limit. Downloads aren't limited by +/// [`MAX_SHARED_FILES`], as versions published by servers can have more files. +pub(crate) const MAX_SHARED_FILES_TOTAL_SIZE: u64 = 2 * 1024 * 1024 * 1024; pub(crate) const MAX_CONFIG_BUNDLE_ENTRIES: usize = 4096; pub(crate) const MAX_CONFIG_BUNDLE_FILE_SIZE: u64 = 512 * 1024 * 1024; pub(crate) const MAX_CONFIG_BUNDLE_TOTAL_SIZE: u64 = 512 * 1024 * 1024; From 8afed6d74e38de42be04d64ea57ee08a2442ff39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Talbot?= <108630700+fetchfern@users.noreply.github.com> Date: Sun, 15 Nov 2026 13:11:09 -0500 Subject: [PATCH 2/2] chore: more consistent limits --- packages/app-lib/src/api/instance.rs | 6 +++--- .../src/api/instance/shared/content.rs | 7 +++++-- .../app-lib/src/api/instance/shared/mod.rs | 9 +++------ .../app-lib/src/install/shared_instance.rs | 20 +++++++++---------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/app-lib/src/api/instance.rs b/packages/app-lib/src/api/instance.rs index 03b0bda55f7..c8f98db1252 100644 --- a/packages/app-lib/src/api/instance.rs +++ b/packages/app-lib/src/api/instance.rs @@ -80,9 +80,9 @@ pub use self::screenshots::{ pub(crate) use self::shared::{ CONFIG_BUNDLE_FILE_TYPE, CONFIG_DIRECTORY, CONFIG_FILE_EXTENSIONS, CONFIG_FILE_TYPE, CONFIG_SYNC_ENABLED, MAX_CONFIG_BUNDLE_ENTRIES, - MAX_SHARED_FILES_TOTAL_SIZE, is_shareable_file_path, - is_supported_config_file, read_bounded_config_bundle_entry, - shared_instance_update_data, shared_modpack_files, + is_shareable_file_path, is_supported_config_file, + read_bounded_config_bundle_entry, shared_instance_update_data, + shared_modpack_files, }; pub use self::shared::{ SharedInstanceExternalFilePreview, SharedInstanceInstallPreview, diff --git a/packages/app-lib/src/api/instance/shared/content.rs b/packages/app-lib/src/api/instance/shared/content.rs index d4ee1facf08..1d2e15dea52 100644 --- a/packages/app-lib/src/api/instance/shared/content.rs +++ b/packages/app-lib/src/api/instance/shared/content.rs @@ -95,20 +95,23 @@ fn newest_config_files<'a>( fn ensure_config_limits( external_files: &[ExternalFileResponse], ) -> crate::Result<()> { + let mut count = 0; let mut size = 0_u64; for file in external_files .iter() .filter(|file| file.file_type == CONFIG_FILE_TYPE) { + count += 1; size = size.saturating_add( file.file_size .and_then(|size| u64::try_from(size).ok()) .unwrap_or(u64::MAX), ); } - if size > MAX_SHARED_FILES_TOTAL_SIZE { + if count > MAX_SHARED_FILES || size > MAX_SHARED_FILES_TOTAL_SIZE { bail!(crate::ErrorKind::InputError( - "shared instance files exceed the size limit".to_string(), + "shared instance files exceed the size or file count limit" + .to_string(), )); } Ok(()) diff --git a/packages/app-lib/src/api/instance/shared/mod.rs b/packages/app-lib/src/api/instance/shared/mod.rs index 76501a1bfd0..89ecf77b33b 100644 --- a/packages/app-lib/src/api/instance/shared/mod.rs +++ b/packages/app-lib/src/api/instance/shared/mod.rs @@ -37,13 +37,10 @@ pub(crate) const CONFIG_BUNDLE_FILE_TYPE: &str = "configs"; pub(crate) const CONFIG_FILE_TYPE: &str = "config"; pub(crate) const CONFIG_SYNC_ENABLED: bool = true; pub(crate) const CONFIG_DIRECTORY: &str = "config"; -/// Number of files an owner can select to share in a version. The backend has -/// no file count limit, this keeps the version creation body under its size -/// limit. +/// Number of shared files in a version, when publishing and downloading. pub(crate) const MAX_SHARED_FILES: usize = 16384; -/// Largest total size of a version's shared files, matching the backend's -/// per-version external file limit. Downloads aren't limited by -/// [`MAX_SHARED_FILES`], as versions published by servers can have more files. +/// Total size of a version's shared files when publishing and downloading, +/// matching the backend's per-version external file limit. pub(crate) const MAX_SHARED_FILES_TOTAL_SIZE: u64 = 2 * 1024 * 1024 * 1024; pub(crate) const MAX_CONFIG_BUNDLE_ENTRIES: usize = 4096; pub(crate) const MAX_CONFIG_BUNDLE_FILE_SIZE: u64 = 512 * 1024 * 1024; diff --git a/packages/app-lib/src/install/shared_instance.rs b/packages/app-lib/src/install/shared_instance.rs index ab81caba15d..786dfe2b0d6 100644 --- a/packages/app-lib/src/install/shared_instance.rs +++ b/packages/app-lib/src/install/shared_instance.rs @@ -13,8 +13,7 @@ use super::runner::{ use crate::ErrorKind; use crate::api::instance::{ CONFIG_BUNDLE_FILE_TYPE, CONFIG_DIRECTORY, CONFIG_FILE_TYPE, - CONFIG_SYNC_ENABLED, MAX_CONFIG_BUNDLE_ENTRIES, - MAX_SHARED_FILES_TOTAL_SIZE, is_shareable_file_path, + CONFIG_SYNC_ENABLED, MAX_CONFIG_BUNDLE_ENTRIES, is_shareable_file_path, is_supported_config_file, read_bounded_config_bundle_entry, shared_modpack_files, }; @@ -40,7 +39,7 @@ use uuid::Uuid; const DEFAULT_SERVER_ICON: &[u8] = include_bytes!( "../../../assets/external/illustrations/minecraft_server_icon.png" ); -const MAX_SHARED_INSTANCE_EXTERNAL_FILE_SIZE: u64 = 500 * 1024 * 1024; +const MAX_SHARED_INSTANCE_CONFIG_BUNDLE_SIZE: u64 = 500 * 1024 * 1024; const MAX_SHARED_INSTANCE_INITIAL_BUFFER_SIZE: u64 = 8 * 1024 * 1024; const SHARED_INSTANCE_CONTENT_DOWNLOAD_CONCURRENCY: usize = 4; const SHARED_INSTANCE_FILE_DOWNLOAD_CONCURRENCY: usize = 64; @@ -1505,9 +1504,11 @@ async fn install_shared_instance_external_file( validate_shared_instance_external_file_name(&file.file_name)?; - if file.file_size > MAX_SHARED_INSTANCE_EXTERNAL_FILE_SIZE { + if file.file_type == CONFIG_BUNDLE_FILE_TYPE + && file.file_size > MAX_SHARED_INSTANCE_CONFIG_BUNDLE_SIZE + { bail!(ErrorKind::InputError(format!( - "shared instance external file {} exceeds the maximum size", + "shared instance config bundle {} exceeds the maximum size", file.file_name ))); } @@ -1598,8 +1599,7 @@ async fn install_shared_instance_external_file( Ok(()) } -/// Shared files can be up to the version's size limit, so they are streamed to -/// disk rather than held in memory. +/// Shared files are streamed to disk rather than held in memory. async fn install_shared_instance_file( writer: &crate::api::instance::InstanceFileWriter, file: &SharedInstanceExternalFileData, @@ -1610,11 +1610,9 @@ async fn install_shared_instance_file( downloaded.add(file.file_size); return Ok(()); } - if !is_shareable_file_path(&file.file_name) - || file.file_size > MAX_SHARED_FILES_TOTAL_SIZE - { + if !is_shareable_file_path(&file.file_name) { bail!(ErrorKind::InputError(format!( - "shared instance file {} is unsupported or too large", + "shared instance file {} is unsupported", file.file_name ))); }