From:             billy dot becker at gmail dot com
Operating system: gentoo linux 2.4.28-gentoo-r2
PHP version:      5.0.3
PHP Bug Type:     Variables related
Bug description:  binary data in $_POST[] is corrupt

Description:
------------
I have a form that submits a wavfile as a variable. The form uses enctype
application/form-data-urlencoded. Normal variables (integer and string)
get tranmitted fine and I can access them normally from $_POST. 
However, my wavfile is coming through corrupt. The bug is that although
the documentation says that PHP does only a urldecode before populating
the $_POST array, something else must be happening in addition.

However, If I manually parse the $HTTP_RAW_POST_DATA string, I can pull my
data out, urldecode() it, and the data is fine. When I compare the
urldecoded RAW_POST_DATA to the $_POST data, I find that the $_POST data
has man low-bit characters replaced with high-bit characters, and the
$_POST data has about 200bytes of extra information strewn throughout the
string. 

So, the data is getting transmitted to the server fine, and PHP see's it
fine, but it does something when it puts it into the $_POST array to
corrupt the data.

I started a thread on comp.lang.php named "how does PHP5 process POST data
in creating $_POST array?"
this link may or may not work:
http://groups-beta.google.com/group/comp.lang.php/browse_frm/thread/01636851f3909135/22e6b7fa4724b4e6#22e6b7fa4724b4e6

I'm not sure how you will be able to reproduce the error without having
access to a source that will send wav data as a form variable. 

Let me know if there is anything else I can do or give you to help fix
this bug.

Reproduce code:
---------------
Assuming you have a source that has posted a wav file with the variable
name: message

this code will show you the difference:

function &parse_http_raw_post_data(&$data, $split1str = '&', $split2str =
'=')
       {
           $split1dat = explode($split1str, $data);
           $num = count($split1dat);
           
           if (! $num) { return false; }
           
           for ($i = 0; $i < $num; $i++) {
               $split2dat=explode($split2str, $split1dat[$i]);
               $ret[$split2dat[$i]] = $split2dat[$i + 1];
           }
           return $ret;
       }

$rawdata=$HTTP_RAW_POST_DATA;
$parsedata=parse_http_raw_post_data($rawdata);
$wavdata=$parsedata['message'];

$postdata=$_POST['message'];

file_put_contents("$writepath/$filename-raw.wav", $wavdata);
file_put_contents("$writepath/$filename-post.wav", $postdata);
file_put_contents("$writepath/$filename-u.wav",   urldecode($wavdata));


Expected result:
----------------
wavdata and postdata should be exactly the same.

Actual result:
--------------
wavdata contains: RIFFFóWAVEfmt @data óÿþÿÿÿÿÿþÿÿÿÿÿþ....

postdata contains: RIFFFó\0\0WAVEfmt [EMAIL PROTECTED]@\0\0\\0\0\0data
ó\....

there's a lot more to the output, but that's the gist of it. PHP is
inserting lots of \0 where it doesn't need to be.

I can send you the two files to compare if you wish.

-- 
Edit bug report at http://bugs.php.net/?id=33006&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33006&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33006&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33006&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=33006&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=33006&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=33006&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=33006&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=33006&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=33006&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=33006&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=33006&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=33006&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=33006&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=33006&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=33006&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=33006&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=33006&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=33006&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=33006&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=33006&r=mysqlcfg

Reply via email to