Error
Pull Request for # 6397

User tests: Successful: Unsuccessful:

avatar nikosdion
nikosdion
16 Mar 2015

This PR fixes gh-6397 "JFilterInput::isSafeFile() fail on very deep $_FILES array"

Testing instructions

        <field type="file" name="document"  label="Document" />
        <fields name="files">
            <fields name="files0">
                <field type="file" name="file"  label="File 1" />
            </fields>
            <fields name="files1">
                <field type="file" name="file"  label="File 2" />
            </fields>
            <fields name="files2">
                <field type="file" name="file"  label="File 3" />
            </fields>
        </fields>
        <fields name="images">
            <fields name="images0">
                <field type="file" name="file"  label="Images 1" />
            </fields>
            <fields name="images1">
                <field type="file" name="file"  label="Images 2" />
            </fields>
        </fields>
  • Open the file administrator/components/com_helloworld/controllers/helloworld.php and add the following between the two curly braces
    public function save($key = null, $urlVar = null)
    {
        $app = JFactory::getApplication();
        $files = $app->input->files->get('jform');

        die('CHECK');

        return parent::save($key, $urlVar); // TODO: Change the autogenerated stub
    }
  • Go to Global Configuration and set Error Reporting to Development
  • Go to Components, Hello World and click on the "Hello, world" link to edit the item.
  • Click each file selection field and choose a small image from your computer. It's best to select files where each one is less than 100Kb to prevent upload issues with PHP itself.
  • Click on the Save & Close button

Result before the patch
A lot of PHP warnings

Result after the patch
No PHP warnings, just the word "CHECK" printed on your page

Technical notes

There were two corrective actions taken:

  • The safe file check was moved into get(). This may have a performance impact on unoptimised code calling $app->input->files->get() repeatedly over the same files, but there's no work around due to the way PHP reports uploaded files. Sorry :(

  • The JFilterInput::isSafeFile method was modified to handle nested file arrays, either in the raw $_FILES format or as nested arrays of file descriptors (these are the only two possible variations that exist)

Signed-off-by: Nicholas K. Dionysopoulos nicholas@akeebabackup.com

avatar nikosdion nikosdion - open - 16 Mar 2015
avatar brianteeman brianteeman - change - 16 Mar 2015
Rel_Number 6397
Relation Type Pull Request for
Build .
avatar Fedik Fedik - test_item - 16 Mar 2015 - Tested successfully
avatar Fedik
Fedik - comment - 16 Mar 2015

thanks @nikosdion

test
work good

avatar brianteeman
brianteeman - comment - 16 Mar 2015

@nikosdion travis isnt happy


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6454.
avatar nikosdion
nikosdion - comment - 16 Mar 2015

It's not really my fault. Travis chokes on a line I copied verbatim from JInputFiles. Apparently core code doesn't conform to the core coding standards... Anyway, I updated the PR to make Travis a happy chap.

avatar brianteeman
brianteeman - comment - 16 Mar 2015

I only said travis wasnt happy. I did not apportion blame :)

avatar nikosdion
nikosdion - comment - 16 Mar 2015

I know, Brian. Let me and Michael complain about the state of the core :)

avatar zero-24 zero-24 - change - 16 Mar 2015
Status New Pending
Build . staging
Easy No Yes
avatar zero-24 zero-24 - change - 16 Mar 2015
Category Libraries
avatar nikosdion
nikosdion - comment - 16 Mar 2015

@wilsonge I fixed the alignment

avatar wilsonge wilsonge - change - 16 Mar 2015
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2015-03-16 21:40:02
avatar wilsonge wilsonge - close - 16 Mar 2015
avatar wilsonge wilsonge - reference | - 16 Mar 15
avatar wilsonge wilsonge - merge - 16 Mar 2015
avatar wilsonge wilsonge - close - 16 Mar 2015
avatar Kubik-Rubik
Kubik-Rubik - comment - 20 Mar 2015

@cheesegrits We need your feedback ASAP. Thanks!

Add a Comment

Login with GitHub to post a comment