php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36413 Win32 GD imagepng(): bad output to browser failure
Submitted: 2006-02-16 11:11 UTC Modified: 2006-02-16 11:48 UTC
From: smartbitcalc at hotmail dot com Assigned:
Status: Not a bug Package: GD related
PHP Version: 5CVS-2006-02-16 (snap) OS: Win32 (98SE, XPH/SP1)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: smartbitcalc at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-02-16 11:11 UTC] smartbitcalc at hotmail dot com
Description:
------------
Win32 GD imagepng() outputs bad data to the browser when the source or any included file has extraneous whitespace surrounding the <?php ?> tags. 

Tested Systems:

Windows 98 SE 
PHP 5CVS2006-Feb-15(snap), PHP 5.1.2, PHP 4.3.4RC1
MSIE 5.0, Firefox 1.0.6
	
Windows XP Home SP1
PHP 4.3.11, MSIE 6.0 (breaks on space|crlf before <?php, space+crlf after ?>)


Reproduce code:
---------------
test.php:

<?php 
// include("testinc.php");
$text = "Happy Happy Joy Joy";
$test = ImageCreate(160,24);
ImageFill($test,0,0,ImageColorAllocate($test,0,0,0));
ImageString($test,4,4,4,$text,ImageColorAllocate($test,255,255,255));
header("Content-type: image/png");
imagepng($test); 
?>

testinc.php:

<?php 
$gettysburg = "Four score and seven years ago..."; 
?>_ <-- note: insert whitespace (0x20) after closing tag

Expected result:
----------------
Run test.php as listed and the browser displays the image as expected. Uncomment the include file, save and run test.php again, and the browser displays a "broken picture" icon. If you remove the trailing space from testinc.php the browser displays the image, but if you insert a space or a carriage return before the opening tag of either file, the image is "broken" again. (Firefox gives you the message 'The image "http://localhost/test.php" cannot be displayed, because it contains errors' rather than a broken image icon, but the cause and effect are the same.)

Actual result:
--------------
Speculation: the problem is actually intermittent (or appears to be) but at least this is verifiable. I have a hunch that the extraneous whitespace is somehow finding its way to the output buffer as the source is being parsed.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-16 11:16 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Of course it does this... you're outputting extra space, why should PHP not do this? This is not a bug.
 [2006-02-16 11:48 UTC] smartbitcalc at hotmail dot com
What a quick reply! Thanks, Derick. However -- 

The ability to output an image directly to the browser is exclusive to PHP's implementation of GD. Wouldn't it be a good idea to, say, update either the documentation or the library so that people don't keep reporting the same "bogus" issue?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 23:01:31 2024 UTC