php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31575 fpassthru, binary mode
Submitted: 2005-01-16 18:56 UTC Modified: 2005-01-16 21:41 UTC
From: kingoleg at mail dot ru Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.10 OS: Linux version 2.4.20-8,Red Hat
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: kingoleg at mail dot ru
New email:
PHP Version: OS:

 

 [2005-01-16 18:56 UTC] kingoleg at mail dot ru
Description:
------------
It seems, that fpassthru() is not binary safe


Reproduce code:
---------------
First 8 bytes of file (PNG image) on disk:

"89 50 4E 47 0D 0A 1A 0A"

<?php
//...
$f = @fopen( $filepath, "rb" );
@fpassthru ($f);
//...die();
?>

Expected result:
----------------
First 8 bytes of saved file via browser:

"89 50 4E 47 0D 0A 1A 0A"

Actual result:
--------------
First 8 bytes of saved file via browser:

"0A 89 50 4E 47 0A 1A 0A"

PS. Other bytes of files are equal.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-16 19:32 UTC] wez@php.net
You've probably got a newline at the top of your script, before the <?php, or a trailing newline from some include or auto-prepend file.
 [2005-01-16 20:10 UTC] kingoleg at mail dot ru
No.

Right before @fpassthru ($f); headers sends. So, it can not be a new line before fpassthru, otherwise header(""); write error message. But there is no error messages in error_log, in browset output. And headers are right.
 [2005-01-16 20:11 UTC] wez@php.net
Comment out the fpassthru() call and look at the page output.
 [2005-01-16 20:58 UTC] kingoleg at mail dot ru
Sorry. I'm found it. It is not a bug.

The output of script was buffered by ob_start(); So header() does not send warning. After I turned off buffering, I find a line out of php section in config file of this soft.

With commented fpassthru() it outputs "\n\n".
 [2005-01-16 21:41 UTC] tony2001@php.net
No bug -> bogus.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 05 02:01:35 2025 UTC