From f837fb4fa8ce61010deeaf54e4b13deffc5ec401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gigarun=20ing=C3=A9nierie?= Date: Fri, 14 Nov 2025 19:05:18 +0400 Subject: [PATCH] Fix: Correct unit comparison bug in webportal document download (#36256) The file size check was comparing bytes (from dol_filesize) directly with kilobytes (from MAIN_SECURITY_MAXFILESIZE_DOWNLOADED config), causing false positives that blocked downloads of small files. Example: A 94 KB file (96678 bytes) was rejected because 96678 > 20480, even though the limit was actually 20480 KB (20 MB). Changes: - Convert KB limit to bytes before comparison: $fileSizeMax * 1024 - Improve error message to display file size in KB for consistency - Add detailed logging with both bytes and KB values Fixes: Files under the configured limit are now correctly allowed to download --- .../webportal/controllers/document.controller.class.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/webportal/controllers/document.controller.class.php b/htdocs/webportal/controllers/document.controller.class.php index f252ae722bf..50ca6690a36 100644 --- a/htdocs/webportal/controllers/document.controller.class.php +++ b/htdocs/webportal/controllers/document.controller.class.php @@ -214,9 +214,11 @@ class DocumentController extends Controller $fileSize = dol_filesize($fullpath_original_file); $fileSizeMax = getDolGlobalInt('MAIN_SECURITY_MAXFILESIZE_DOWNLOADED'); - if ($fileSizeMax && $fileSize > $fileSizeMax) { - dol_syslog('ErrorFileSizeTooLarge: ' . $fileSize); - print 'ErrorFileSizeTooLarge: ' . $fileSize . ' (max ' . $fileSizeMax . ' Kb)'; + if ($fileSizeMax && $fileSize > ($fileSizeMax * 1024)) { + // FIX: Convert limit from Ko to bytes for proper comparison + $fileSizeKb = round($fileSize / 1024, 2); + dol_syslog('ErrorFileSizeTooLarge: ' . $fileSize . ' bytes (' . $fileSizeKb . ' Kb) - max allowed: ' . $fileSizeMax . ' Kb'); + print 'ErrorFileSizeTooLarge: ' . $fileSizeKb . ' Kb (max ' . $fileSizeMax . ' Kb)'; exit; }