php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78965 print causes segmentation error when client lost connection to server.
Submitted: 2019-12-15 23:36 UTC Modified: -
From: intlwangzp at gmail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 7.3.12 OS: Debian GNU/Linux 10 (buster)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-12-15 23:36 UTC] intlwangzp at gmail dot com
Description:
------------
php corrupts with the following error log:
[Sun Dec 15 23:37:29.394166 2019] [core:notice] [pid 5439] AH00094: Command line: '/usr/sbin/apache2'
[Sun Dec 15 23:45:59.115631 2019] [core:notice] [pid 5439] AH00052: child pid 5444 exit signal Segmentation fault (11)
[Sun Dec 15 23:45:59.115799 2019] [core:notice] [pid 5439] AH00052: child pid 5457 exit signal Segmentation fault (11)
[Sun Dec 15 23:45:59.115901 2019] [mpm_prefork:notice] [pid 5439] AH00169: caught SIGTERM, shutting down
[Sun Dec 15 23:45:59.280035 2019] [mpm_prefork:notice] [pid 5615] AH00163: Apache/2.4.38 (Debian) configured -- resuming normal operations
[Sun Dec 15 23:45:59.280156 2019] [core:notice] [pid 5615] AH00094: Command line: '/usr/sbin/apache2'

This error happens when I test the video stream function and print the buffer read from a local media file. If client closes the internet connection for example by disconnecting wifi while the video is still playing and data is still downloading, print function will cause a segmentation fault.

The code comes originally from http://infinityquest.com/php-tutorials/program-http-range-in-php/ and the critical line number is #148. If we use echo instead of print, problem is then solved.


Test script:
---------------
// Move the proper place in the file
// And print out the requested piece in chunks
function send_range($handle, $start, $end) {
    $line_length = 4096; // magic number

    if (fseek($handle, $start) === -1) {
        error_log("Error: fseek() fail.");
    }

    $left_to_read = $end - $start + 1;
    do {
        $length = min($line_length, $left_to_read);
        if (($buffer = fread($handle, $length)) !== false) {
            // print $buffer;   // ***** BUG if use print *****
            echo $buffer;       // ***** ok *****
        } else {
            error_log("Error: fread() fail.");
        }
    } while ($left_to_read -= $length);
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-16 06:57 UTC] thedinosaurmail at gmail dot com
in my computer is work ok
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 03:01:28 2024 UTC