php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22810 Incorrectly writes out data.
Submitted: 2003-03-20 20:23 UTC Modified: 2003-04-14 20:41 UTC
From: gfraley5 at earthlink dot net Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.3.2 latest build OS: Windows XP / Linux
Private report: No CVE-ID: None
 [2003-03-20 20:23 UTC] gfraley5 at earthlink dot net
The following code works correctly on 4.3.1 (and prior) but does not appear to work correctly on 4.3.2RC1.  I have only tested this on Windows XP.

<?
	$fp = fopen("php432.csv.php",'r') or die("Problem");
	while ($data = fgetcsv($fp,1024,",")) {
		$row++;
		if ($row<1) continue;
		$gcf = $data;
	}
	fclose($fp);

	$fp = fopen("php432.csv.php",'w') or die("Problem");
	flock($fp,2);
	for ($i=0;$i<count($gcf);$i++) {
		if ($i==0) $prefx = "<? Header(\"HTTP/1.0 403 Forbidden\");exit; ?>\n";
		else $prefx = "";
		fwrite($fp,$prefx.$gcf[$i].',');
		if ($i<count($gcf)-1) fwrite($fp,',');		
	}
	flock($fp,3);
	fclose($fp);
?>


Here is a simple example of the file that is read in (php432.csv.php):

<? Header("HTTP/1.0 403 Forbidden");exit; ?>
1043203275,localhost,2003-01-21,20:41:15,Anonymous,,,,,,,,blank,Test,,

When run under 4.3.1, it correctly writes out
<? Header("HTTP/1.0 403 Forbidden");exit; ?>
1043203275,localhost,2003-01-21,20:41:15,Anonymous,,,,,,,,blank,Test,,

However, under 4.3.2RC1, it truncates the last digit (5) from the first field.  It writes out
<? Header("HTTP/1.0 403 Forbidden");exit; ?>
104320327,localhost,2003-01-21,20:41:15,Anonymous,,,,,,,,blank,Test,,

There is other erratic behavior also.  If I modify the code to include a header row in line 2, and modify the code accordingly, it will skip the first comma separator like this:

1043203275localhost,2003-01-21,20:41:15,Anonymous,,,,,,,,blank,Test,,.  

I have not included that code for brevity.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-25 17:50 UTC] iliaa@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

Your code has a bug, I've revised your code and now the output is identical to the input. It should be noted that even before any modifications the generated output was indetical to the one of PHP 4.2.3

Here is the revised write code:
$fp = fopen("out",'w') or die("Problem");
$prefx = "<? Header(\"HTTP/1.0 403 Forbidden\");exit; ?>\n";
$csv_out = implode(',', $gcf);
fwrite($fp,$prefx.$csv_out);
 fclose($fp);

 [2003-03-25 18:07 UTC] gfraley5 at earthlink dot net
Thank you for correcting the snippet I tried to put together to minimize the amount of code to submit the bug.  However, in my full code the error is there and my code works fine in all previous releases back to 4.1.  I am not arguing with you, just stating a fact.  I will try to redefine the error/bug.  I am curious, however, as to why the code runs correctly under 4.3.1?
 [2003-03-25 19:06 UTC] gfraley5 at earthlink dot net
I just downloaded the latest CVS and tried my application under it.  Now, something between my php code, Apache, and this latest CVS is causing Apache.exe to crash.
 [2003-03-30 23:11 UTC] gfraley5 at earthlink dot net
Just tried the 330 cvs and Apache is still crashing.
 [2003-04-02 21:00 UTC] gfraley5 at earthlink dot net
It crashes Apache on Windows 2000 also
 [2003-04-14 20:41 UTC] gfraley5 at earthlink dot net
I was finally able to isolate the code that was causing this.  I submitted the actual problem here http://bugs.php.net/?id=23201&edit=2 and it should be fixed in the next CVS.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 02:01:29 2024 UTC