Bug #78965 [NEW]: print causes segmentation error when client lost connection to server.

From: Date: Sun, 15 Dec 2019 23:36:54 +0000
Subject: Bug #78965 [NEW]: print causes segmentation error when client lost connection to server.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224318@lists.php.net to get a copy of this message
From: intlwangzp at gmail dot com Operating system: Debian GNU/Linux 10 (buster) PHP version: 7.3.12 Package: *General Issues Bug Type: Bug Bug description:print causes segmentation error when client lost connection to server. 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); } -- Edit bug report at https://bugs.php.net/bug.php?id=78965&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=78965&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=78965&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=78965&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=78965&r=needscript Try newer version: https://bugs.php.net/fix.php?id=78965&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=78965&r=support Expected behavior: https://bugs.php.net/fix.php?id=78965&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=78965&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=78965&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=78965&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=78965&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=78965&r=dst IIS Stability: https://bugs.php.net/fix.php?id=78965&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=78965&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=78965&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=78965&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=78965&r=mysqlcfg

« previous php.bugs (#224318) next »