diff --git a/htdocs/core/filemanagerdol/browser/default/frmupload.php b/htdocs/core/filemanagerdol/browser/default/frmupload.php index 17a2be8725b..7badd1763c3 100644 --- a/htdocs/core/filemanagerdol/browser/default/frmupload.php +++ b/htdocs/core/filemanagerdol/browser/default/frmupload.php @@ -134,7 +134,10 @@ function OnUploadCompleted( errorNumber, data ) alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + data + '"' ); break; case 202: - alert( 'Invalid file (Bad extension)' ); + alert( 'Invalid file (Bad extension reported by image_format_supported or other)' ); + break; + case 205: + alert( 'Invalid file (Bad file reported by DetectHtml)' ); break; default: alert( 'Error on file upload. Error number: ' + errorNumber ); diff --git a/htdocs/core/filemanagerdol/connectors/php/connector.lib.php b/htdocs/core/filemanagerdol/connectors/php/connector.lib.php index 3854d3f8b6e..91c93c531eb 100644 --- a/htdocs/core/filemanagerdol/connectors/php/connector.lib.php +++ b/htdocs/core/filemanagerdol/connectors/php/connector.lib.php @@ -323,6 +323,8 @@ function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '') //$sFileName = SanitizeFileName($sFileName); $sFileName = dol_sanitizeFileName($sFileName); + dol_syslog("FileUpload sFileName=".$sFileName); + $sOriginalFileName = $sFileName; // Get the extension. @@ -339,7 +341,7 @@ function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '') }*/ if (!$permissiontouploadmediaisok) { dol_syslog("connector.lib.php Try to upload a file with no permission"); - $sErrorNumber = '202'; + $sErrorNumber = '204'; } include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; @@ -397,9 +399,9 @@ function FileUpload($resourceType, $currentFolder, $sCommand, $CKEcallback = '') $detectHtml = DetectHtml($sFilePath); if ($detectHtml === true || $detectHtml == -1) { // Note that is is a simple test and not reliable. Security does not rely on this. - dol_syslog("connector.lib.php DetectHtml is ko"); + dol_syslog("connector.lib.php DetectHtml is ko detectHtml=".$detectHtml.", we delete the file."); @unlink($sFilePath); - $sErrorNumber = '202'; + $sErrorNumber = '205'; } } } @@ -964,13 +966,11 @@ function DetectHtml($filePath) { $fp = @fopen($filePath, 'rb'); - //open_basedir restriction, see #1906 - if ($fp === false || !flock($fp, LOCK_SH)) { + if ($fp === false) { return -1; } $chunk = fread($fp, 1024); - flock($fp, LOCK_UN); fclose($fp); $chunk = strtolower($chunk); diff --git a/htdocs/core/lib/images.lib.php b/htdocs/core/lib/images.lib.php index ca1c8e8c812..44e4ee3cba5 100644 --- a/htdocs/core/lib/images.lib.php +++ b/htdocs/core/lib/images.lib.php @@ -80,7 +80,7 @@ function getListOfPossibleImageExt($acceptsvg = 0) * * @param string $file Filename * @param int $acceptsvg 0=Default (depends on setup), 1=Always accept SVG as image files - * @return int -1=Not image filename, 0=Image filename but format not supported for conversion by PHP, 1=Image filename with format supported by this PHP + * @return int -1=Not image filename, 0=Image filename but format not supported for conversion by PHP, 1=Image filename with format supported in conversion by this PHP */ function image_format_supported($file, $acceptsvg = 0) {