php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31350 Max reading length of STDIN is 8192bytes
Submitted: 2004-12-30 11:59 UTC Modified: 2004-12-31 01:21 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: gibspam at carnation dot hu Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.10 OS: Redhat Linux 7.1-7.3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gibspam at carnation dot hu
New email:
PHP Version: OS:

 

 [2004-12-30 11:59 UTC] gibspam at carnation dot hu
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



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-31 01:21 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 16:01:37 2025 UTC