View Issue Details

This bug affects 1 person(s).
 6
IDProjectCategoryView StatusLast Update
16855Bug reportsFile managerpublic2020-11-30 11:37
Reporternetdeals Assigned ToDenisChenu  
PrioritynoneSeverityblock 
Status closedResolutionfixed 
Product Version3.25.1 
Summary16855: Upload File MIME Type Check Error
Description

When a survey is set up for users to upload files of certain types, the user is confronted with the error "Sorry, unable to check extension of this file type."

Steps To Reproduce
  1. import the attached survey
  2. click Preview Survey on the survey admin interface
  3. click Upload files button on the lower left corner
  4. click Select file button in the center, navigate to a local folder, select a file with the specified type and will be prompted with the error stating "Sorry, unable to check extension of this file type."
Additional Information

In the survey file, I have specified PDF and XLSX formats, and both triggered the same error.

The only workaround is to edit line 182 in the source file "\limesurvey\application\controllers\UploaderController.php" and turn $disableCheck to true.

TagsNo tags attached.
Attached Files
Bug heat6
Complete LimeSurvey version number (& build)Version 3.25.1 build 201124
I will donate to the project if issue is resolvedNo
BrowserFirefox, ChrEdge
Database type & versionMySQL 5.6.10; innodb 1.2.10
Server OS (if known)Windows NT BUS-APPS 10.0 build 14393 (Windows Server 2016) AMD64
Webserver software & version (if known)Microsoft-IIS/10.0
PHP Version7.4.10

Users monitoring this issue

There are no users monitoring this issue.

Activities

DenisChenu

DenisChenu

2020-11-24 17:59

developer   ~60749

Your server seems to know ico file but not pdf or xlsx file ?

Really strange … but it's a windows server ...

You can force one with magic_database in config.php but don't know how to get one for windows (i test with an old Gnu/Linux/Debian9 and a magic_database from last Gnu/Linux/Fedora version)
https://manual.limesurvey.org/Optional_settings#Upload_files

netdeals

netdeals

2020-11-25 16:40

reporter   ~60757

Strange maybe, but it doesn't look like adding the magic_file alone in config.php helps. I do not know how to set up the magic_database entry either. But before reaching out to sys admin for some much needed magic, I decided to wade into the source code.
After line-by-line debugging, it appears that line 181 in the source file "\limesurvey\application\controllers\UploaderController.php" (https://github.com/LimeSurvey/LimeSurvey/blob/8697d482691c59dd07b487085b42b5dfae0f4462/application/controllers/UploaderController.php#L186 of the equivalent script for version 4) generated a null string $extByMimeType.
I agree with your comment that the subsequent checks appear to suggest "Your server seems to know ico file but not pdf or xlsx file". I too thought that was odd so I carefully compared the code blocks checking the uploaded file versus checking the ico file. The difference lies in the lack of a file extension in the offending line.
It appears the magic cure I have been after is to add the file extension to the aforementioned line 181 so that it reads as follows.
$extByMimeType = LSFileHelper::getExtensionByMimeType($_FILES['uploadfile']['tmp_name']. '.' . $pathinfo['extension'], null);
Without adding the file extension, line 181 was checking a temporary file stored in C:\Windows\Temp without any file extension, leading to the null string $extByMimeType. That line without the file extension might have worked for you and others on different flavors of Unix but it appears necessary at least in IIS land.
In any event, revising line 181 to add the file extension is better than revising line 182 to turn $disableCheck to true.

Thanks so much for your time and comment, Denis. Your effort is much appreciated.

image.png (7,706 bytes)   
image.png (7,706 bytes)   
DenisChenu

DenisChenu

2020-11-26 08:05

developer   ~60760

You're right …

https://github.com/LimeSurvey/LimeSurvey/blob/8697d482691c59dd07b487085b42b5dfae0f4462/application/core/LSFileHelper.php#L43 don't send null at the 3rd param

Thanks a lot for your report.

I think i add a config.php to allow disable extension checking. ONLY with php since it can be a security issue …

DenisChenu

DenisChenu

2020-11-27 19:48

developer   ~60788

Fix committed to 3.x-LTS branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=30755

DenisChenu

DenisChenu

2020-11-27 19:50

developer   ~60789

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=30756

DenisChenu

DenisChenu

2020-11-29 10:22

developer   ~60792

@netdeals can you confirm the issue was fixed using this patch ?
if(empty(LSFileHelper::getMimeType(APPPATH."favicon.ico", null, null)) ) {

lime_release_bot

lime_release_bot

2020-11-30 11:37

administrator   ~60801

Fixed in Release 4.3.29+201130

Related Changesets

LimeSurvey: 3.x-LTS c25ffd2b

2020-11-27 19:47:53

DenisChenu

Details Diff
Fixed issue 16855: Upload File MIME Type Check Error
Dev: use getMimeType directly without extension
Dev: test more simple on FileHelper
Affected Issues
16855
mod - application/controllers/UploaderController.php Diff File
mod - application/core/LSFileHelper.php Diff File

LimeSurvey: master 9aa7ca63

2020-11-27 19:47:53

DenisChenu

Details Diff
Fixed issue 16855: Upload File MIME Type Check Error
Dev: use getMimeType directly without extension
Dev: test more simple on FileHelper
Dev: cherry-picked
Affected Issues
16855
mod - application/controllers/UploaderController.php Diff File
mod - application/core/LSFileHelper.php Diff File

Issue History

Date Modified Username Field Change
2020-11-23 17:07 netdeals New Issue
2020-11-23 17:07 netdeals File Added: bug.tracker.upload.project.1.pdf.xlsx.png
2020-11-23 17:07 netdeals File Added: bug.tracker.upload.project.1.pdf.xlsx.lss
2020-11-24 17:59 DenisChenu Note Added: 60749
2020-11-25 16:40 netdeals Note Added: 60757
2020-11-25 16:40 netdeals File Added: image.png
2020-11-26 08:03 DenisChenu Assigned To => DenisChenu
2020-11-26 08:03 DenisChenu Status new => assigned
2020-11-26 08:05 DenisChenu Note Added: 60760
2020-11-27 19:48 DenisChenu Changeset attached => LimeSurvey 3.x-LTS c25ffd2b
2020-11-27 19:48 DenisChenu Note Added: 60788
2020-11-27 19:48 DenisChenu Resolution open => fixed
2020-11-27 19:50 DenisChenu Changeset attached => LimeSurvey master 9aa7ca63
2020-11-27 19:50 DenisChenu Note Added: 60789
2020-11-29 10:22 DenisChenu Status assigned => ready for testing
2020-11-29 10:22 DenisChenu Note Added: 60792
2020-11-30 11:37 lime_release_bot Note Added: 60801
2020-11-30 11:37 lime_release_bot Status ready for testing => closed