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
This commit is contained in:
Gigarun ingénierie
2025-11-14 19:05:18 +04:00
committed by GitHub
parent 545a0f5532
commit f837fb4fa8

View File

@@ -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;
}