From 0cbbb6b7ac2b26ce278fc57cbbdf892188a979f1 Mon Sep 17 00:00:00 2001 From: BillionClaw Date: Tue, 17 Mar 2026 04:39:18 +0800 Subject: [PATCH] fix: ARMv7 32-bit compilation overflow The constant 10 * 1024 * 1024 * 1024 (10 GB) overflows on 32-bit systems where usize is 32-bit (max ~4GB). This caused compilation failures on ARMv7 architecture. Fix by using architecture-appropriate limits: - 64-bit: 10 GB (unchanged) - 32-bit: 1 GB (safe maximum for 32-bit usize) Fixes #206 --- src/common/config.rs | 8 +++++++- src/interfaces/api/routes.rs | 9 ++++++++- src/main.rs | 9 +++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/common/config.rs b/src/common/config.rs index dd74f372..e785dc86 100755 --- a/src/common/config.rs +++ b/src/common/config.rs @@ -207,12 +207,18 @@ pub struct StorageConfig { impl Default for StorageConfig { fn default() -> Self { + // Architecture-appropriate max upload size to avoid overflow on 32-bit systems + const MAX_UPLOAD_SIZE: usize = if cfg!(target_pointer_width = "64") { + 10 * 1024 * 1024 * 1024 // 10 GB on 64-bit + } else { + 1024 * 1024 * 1024 // 1 GB on 32-bit + }; Self { root_dir: "storage".to_string(), chunk_size: 1024 * 1024, // 1 MB parallel_threshold: 100 * 1024 * 1024, // 100 MB trash_retention_days: 30, // 30 days - max_upload_size: 10 * 1024 * 1024 * 1024, // 10 GB + max_upload_size: MAX_UPLOAD_SIZE, } } } diff --git a/src/interfaces/api/routes.rs b/src/interfaces/api/routes.rs index 1c9cc287..76eda01a 100755 --- a/src/interfaces/api/routes.rs +++ b/src/interfaces/api/routes.rs @@ -150,7 +150,14 @@ pub fn create_api_routes(app_state: &Arc) -> Router> { get(FileHandler::get_thumbnail).put(FileHandler::upload_thumbnail), ) .route("/{id}/metadata", get(FileHandler::get_file_metadata)) - .layer(DefaultBodyLimit::max(10 * 1024 * 1024 * 1024)) // 10 GB for file uploads + .layer(DefaultBodyLimit::max({ + // Use architecture-appropriate body limit: 10 GB on 64-bit, 1 GB on 32-bit + #[cfg(target_pointer_width = "64")] + const FILE_BODY_LIMIT: usize = 10 * 1024 * 1024 * 1024; + #[cfg(target_pointer_width = "32")] + const FILE_BODY_LIMIT: usize = 1024 * 1024 * 1024; + FILE_BODY_LIMIT + })) // for file uploads .with_state(app_state.clone()); // File operations with trash support diff --git a/src/main.rs b/src/main.rs index 0048b984..c0043ced 100755 --- a/src/main.rs +++ b/src/main.rs @@ -375,9 +375,14 @@ async fn main() -> Result<(), Box> { } } - // Increase the default body limit to 10 GB to allow large file uploads. + // Increase the default body limit to allow large file uploads. + // Uses architecture-appropriate limit: 10 GB on 64-bit, 1 GB on 32-bit. // Without this Axum caps Multipart bodies at 2 MB. - app = app.layer(DefaultBodyLimit::max(10 * 1024 * 1024 * 1024)); + #[cfg(target_pointer_width = "64")] + const BODY_LIMIT: usize = 10 * 1024 * 1024 * 1024; // 10 GB + #[cfg(target_pointer_width = "32")] + const BODY_LIMIT: usize = 1024 * 1024 * 1024; // 1 GB + app = app.layer(DefaultBodyLimit::max(BODY_LIMIT)); // ── HTTP compression (gzip + Brotli) ───────────────────────────────── // Negotiates the best encoding via Accept-Encoding. Skips responses