php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44749 FastCGI problems during large HTTP Posts (corruption or hang)
Submitted: 2008-04-16 21:31 UTC Modified: 2008-04-17 22:28 UTC
From: eth at ethaniel dot com Assigned:
Status: Not a bug Package: CGI/CLI related
PHP Version: 5.2.5 OS: Freebsd 7.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: eth at ethaniel dot com
New email:
PHP Version: OS:

 

 [2008-04-16 21:31 UTC] eth at ethaniel dot com
Description:
------------
I use Freebsd 7.0 with lighttpd 1.4.19 and php-cgi 5.2.5 (with suhosin patch).

I noticed, that when I do a large upload (1.2 megabytes) php works unadequately: randomly it either corrupts the upload or just freezes.

So for instance, if I run php-cgi on a tcp port (1026) it successfully accepts all uploads that are given to it from lighttpd and processes them through the script. But randomly (sometimes several times in a row, sometimes one out of 10 requests) it corrupts the post data (several bytes in the center of the 1.2 megabyte block get corrupted - replaced with 00 00 00 hex values). Nothing freezes at this configuration.

If I run php-cgi as a unix socket (/tmp/php.sock) it either accepts the upload (and never shows any sign of corruption, all data is processed normally), or just halts and leaves the connection open (doesn't reply to the current and any new connections either).
Sometimes it just unfreezes after a while and starts accepting new connections, sometimes I just have to respawn php-cgi.

My best guess is that it might have something to do with the freebsd 7.0 socket handling. Maybe not - maybe it really is a bug in php-cgi.

I checked - lighttpd has all the uploaded files uncorrupted. The bad things start happening somewhere between lighttpd and fastcgi php.

Reproduce code:
---------------
Here is the command I use to make the upload from the remote host.

curl -vv -# -s -F "testfile=@debug.jpg" -H "Host: upload.host.ru" -H "Expect:" -H "Content-Type:" -0 1.1.1.1:200/testupload.php

Note the empty Content-type - once I noticed the corruption, I decided to make a test and debug HTTP_RAW_POST_DATA by hand. The corruption was all the way up there.

Expected result:
----------------
The testupload.php script checks the HTTP_RAW_POST_DATA, extracts the uploaded files from mime headers and checks it's md5 value. If MD5 is incorrect, it logs the uploaded file and then I compare it to the normal sample.

Actual result:
--------------
Nothing here.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-17 08:58 UTC] eth at ethaniel dot com
Seems like the problem was in lighttpd.

Setting server.network-backend = "write" in lighttpd.conf solved the problem.
 [2008-04-17 10:59 UTC] eth at ethaniel dot com
server.network-backend = "write" started causing some strange "resource unavailable" errors in the error log, so I changed it to

server.network-backend = "writev" and everything went back to normal.
 [2008-04-17 21:16 UTC] jani@php.net
Your problem is: (with _suhosin_ patch).

 [2008-04-17 22:28 UTC] eth at ethaniel dot com
is Suhosin really that bad?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 03:02:51 2024 UTC