Bug #81589 [NEW]: PHP script on FPM / FastCGI may end prematurely
| From: | peter dot kotuliak at gmail dot com | Date: | Thu, 04 Nov 2021 09:09:21 +0000 |
| Subject: | Bug #81589 [NEW]: PHP script on FPM / FastCGI may end prematurely | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-237537@lists.php.net to get a copy of this message | ||
From: peter dot kotuliak at gmail dot com
Operating system: Linux
PHP version: Irrelevant
Package: FPM related
Bug Type: Bug
Bug description:PHP script on FPM / FastCGI may end prematurely
Description:
------------
Running provided test script (error reporting cannot be Off) on real
webserver (Apache, nginx tested) using php-fpm, ends prematurely.
This is FPM specific bug (e.g. use of Apache handler is OK).
Script "terminates" because FPM sometimes generates empty (zero length)
FCGI record / packet. FCGI specification however states that such a
record may indicate content termination.
Solution is to replace this code in fastcgi.c
} else if (len - limit < (int)(sizeof(req->out_buf) -
sizeof(fcgi_header))) {
if (!req->out_hdr) {
open_packet(req, type);
}
if (limit > 0) {
memcpy(req->out_pos, str, limit);
req->out_pos += limit;
}
if (!fcgi_flush(req, 0)) {
with this
} else if (len - limit < (int)(sizeof(req->out_buf) -
sizeof(fcgi_header))) {
if (limit > 0) {
if (!req->out_hdr) {
open_packet(req, type);
}
memcpy(req->out_pos, str, limit);
req->out_pos += limit;
}
if (!fcgi_flush(req, 0)) {
It solves bug, occurring when stream changes (from OUT to ERR or vice
versa), but having too few bytes left in output buffer (in this case,
first it is called close_packet due to stream change and since limit==0
additional open_packet and close_packet (inside fcgi_flush) is called
with zero content length, which webserver interprets as "request
finished").
Script has to be tested on real webserver (FPM tester used in .phpt does
not copy webserver behavior that well in this case).
Every PHP version is affected.
If you have any questions, or trouble reproducing bug, please contact
me.
Test script:
---------------
<?php
for($i=0;$i<167;$i++){
error_log('PHP is the best programming language');
}
echo 'end';
?>
Expected result:
----------------
string "end"
Actual result:
--------------
empty string
--
Edit bug report at https://bugs.php.net/bug.php?id=81589&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81589&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81589&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81589&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81589&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81589&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81589&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81589&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81589&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81589&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81589&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81589&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81589&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81589&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81589&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81589&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81589&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81589&r=mysqlcfg