php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72932 database sessions causes upload to CRASH if upload progress used
Submitted: 2016-08-23 15:18 UTC Modified: 2016-08-24 09:54 UTC
From: mark at sasoft dot co dot za Assigned:
Status: Wont fix Package: Session related
PHP Version: Irrelevant OS: Windows
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-08-23 15:18 UTC] mark at sasoft dot co dot za
Description:
------------
It appears this bug exists regardless of any version of php or OS or web server. I have physically tested this to occur across:
- Windows 7, Windows Server 2012 R2
- PHP Version 5.3, 5.4, 5.5, 5.6 and 7.0.10 (all binaries downloaded from php.net windows already compiled as NTS x86 and x64)
- Apache 2.2 and IIS (7+8)

My php.ini has been modified only for session.save_handler = user. All other settings left as default.

What happens is that if I submit a form with file upload progress utilisation (ie. name as value from ini_get("session.upload_progress.name")) then the upload actually crashes the script and my error log file contains the contents :

PHP Warning:  Unknown: user session functions not defined in Unknown on line 0
PHP Fatal error:  Unknown: Failed to initialize storage module: user (path: C:\WINDOWS\Temp) in Unknown on line 0

It appears that php is trying to default back to use save_hander=files and then fails. If i COMMENT OUT the PHP_SESSION_UPLOAD_PROGRESS line so that file upload progress is disabled, it works perfectly. It also works perfectly if i set the save_handler back to "files" in my php.ini.

Naturally, even if it didnt generate a fatal error, the file session info would still be inaccessible to my database session if it succeeds in writing to the file.

 

Test script:
---------------
The html form looks like this :

<iframe id="upload_iframe" name="upload_iframe" style="width: 1px; height: 1px; display: block;border:0px;"></iframe>
<form id="myUploadForm" name="myUploadForm" target="upload_iframe" action="uploadFile.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="UID" value="1">
<input type="hidden" value="myUploadForm" name="PHP_SESSION_UPLOAD_PROGRESS">
<input type="file" class="upload" name="file" id="file">
<input type="submit" class="cmi-button small white" value="Upload" onclick="fileUpload.startUploadMonitoring();">
</form>

My session_set_save_handler override for _open looks like this :

function _open() {
    if( ($this->dbc = mysqli_connect(DBSettings::HOSTNAME, DBSettings::USERNAME, DBSettings::PASSWORD)) !== false ) {
      $select_db = mysqli_select_db($this->dbc, DBSettings::DATABASE_SHARED_SERVICES);
      // $set_charset = mysqli_set_charset($this->dbc, DB_CHARSET);
      return( $select_db /*&& $set_charset*/ );
    }
    else {
      trigger_error(mysqli_error($this->dbc), E_USER_ERROR);
    }

    return( false );
  }

(but i think the above handler override is irrelevant to this bug as even if i change the trigger_error to return true rather, it makes no difference as the error occurs BEFORE control is handed over to the USER script)



Expected result:
----------------
it should firstly NOT crash PHP, and secondly it should use the php.ini setting for my database session handler.

my error log file contains the contents :

PHP Warning:  Unknown: user session functions not defined in Unknown on line 0
PHP Fatal error:  Unknown: Failed to initialize storage module: user (path: C:\WINDOWS\Temp) in Unknown on line 0

Actual result:
--------------
my error log file contains the contents :

PHP Warning:  Unknown: user session functions not defined in Unknown on line 0
PHP Fatal error:  Unknown: Failed to initialize storage module: user (path: C:\WINDOWS\Temp) in Unknown on line 0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-24 07:03 UTC] yohgaki@php.net
-Status: Open +Status: Wont fix
 [2016-08-24 07:03 UTC] yohgaki@php.net
First of all, unless there is working session save handler, file upload progress wouldn't work at all.

What do you mean by "then the upload actually crashes the script"? I guess you mean PHP script execution is terminated by "PHP Fatal error:  Unknown: Failed to initialize storage module: user (path: C:\WINDOWS\Temp) in Unknown on line 0".

There will be errors when save handler didn't work. This behavior cannot be changed for reasons.

It seems file upload have problems in 7.0. If this is the case, please comment appropriate bug reports. Thank you.
 [2016-08-24 07:13 UTC] yohgaki@php.net
It seems you needs 3rd party save handlers from memcache or like for upload progress.i.e You need to share upload progress status between web servers. Use these kind of "central database type" save handlers via php.ini.

You don't have to (in fact, you shouldn't) set session.save_handler=files in php.ini. session_set_save_handler() changes the setting and you must call it to use user save handler always.
 [2016-08-24 09:54 UTC] mark at sasoft dot co dot za
In your comment, you say i should not set "session.save_handler=files". I confirm that i have not set it to files anywhere. Rather i have set it to "user" instead.
You also mention that i should actually not set it at all in the php.ini as "user" either but as part of the session_set_save_handler(). I have tested this without setting in the php.ini and have instead put it as part of ini_set() at start of script. Unfortunately this makes no difference and i still get a PHP Fatal error.

I am not using memcache(d) - can you possibly suggest a recognised 3rd party utility that corrects this issue that i am experiencing ?

Thanks
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 19:01:31 2024 UTC