From:             gibspam at carnation dot hu
Operating system: Redhat Linux 7.1-7.3
PHP version:      4.3.10
PHP Bug Type:     Filesystem function related
Bug description:  Max reading length of STDIN is 8192bytes

Description:
------------
I write a script which reads a file from STDIN, and writes it out the
content of it to a new file. It worked fine with php 4.3.4, but when I
upgraded to any newer version, then it failed to read the whole file from
stdin. I expected to read the file into a 128000 bytes buffer but it reads
only 8192 bytes instead of 128000 bytes.

Reproduce code:
---------------
<?
$file_length = 6596594;
define("UPLOAD_BUFFER",128000);

if (!$fp = fopen("test.data","w"))
{
                die("file open error");
}

$count =  (($file_length / UPLOAD_BUFFER));
echo "\nmax i should be: ".$count;
for ($i = 1; $i < $count; $i ++) {
        $str = fread(STDIN, UPLOAD_BUFFER);
        echo "\ni: ".$i." length:".strlen($str);
        fwrite($fp, $str);
}

$remainder = $file_length % UPLOAD_BUFFER;

if (0 != $remainder) {
        $str = fread(STDIN, $remainder);
        echo "\nlast length:".strlen($str);
        fwrite($fp, fread(STDIN, $remainder));
}

fclose($fp);
?>


Expected result:
----------------
If I run my script with this command:
php -q ./my.php < file_with_size_of_6596594_bytes.bin

I expect to get a new file created (test.data), with the same content as
the file_with_size_of_6596594_bytes.bin.

Actual result:
--------------
As a result a new file created (test.data), which is 425984 bytes long.

425984=51*8192+8192

But, it shuld be

6596594=51*128000+68594



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

Reply via email to