#27687 [Opn->Fbk]: Bug Adding Default Charset to "text/*" Content-Type Header
| From: | helly@php.net | Date: | Thu, 25 Mar 2004 08:33:24 +0000 |
| Subject: | #27687 [Opn->Fbk]: Bug Adding Default Charset to "text/*" Content-Type Header | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-56797@lists.php.net to get a copy of this message | ||
ID: 27687
Updated by: helly@php.net
Reported By: msisolak at yahoo dot com
-Status: Open
+Status: Feedback
Bug Type: Unknown/Other Function
Operating System: Windows 2000
PHP Version: 5.0.0RC1
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2004-03-24 23:13:30] msisolak at yahoo dot com
Description:
------------
There is a bug in the sapi_header_op() function in main/sapi.c
(referencing the 5.0.0RC1 line numbers). In the special case for the
Content-Type header starting on line 560 is this code:
size_t len = header_line_len - (ptr - header_line), newlen;
while (*ptr == ' ' && *ptr != '\0') {
ptr++;
}
The mistake is in calculating the len based on the location of ptr, but
then adjusting ptr up to shorten the string to remove leading spaces
without also adjusting len down. The len variable ends up being one
character too long for each space removed from between the colon and
the content type. This extra space propagates through and ends up
causing random extra characters on the end of the Content-Type line in
the output headers (one for each space skipped).
Suggested patch:
--- sapi.c.orig Wed Mar 24 23:07:58 2004
+++ sapi.c Wed Mar 24 23:08:04 2004
@@ -562,6 +562,7 @@
size_t len = header_line_len - (ptr - header_line), newlen;
while (*ptr == ' ' && *ptr != '\0') {
ptr++;
+ len--;
}
#if HAVE_ZLIB
if(!strncmp(ptr, "image/", sizeof("image/")-1)) {
Reproduce code:
---------------
<?php
header("Content-Type: text/plain");
?>
Expected result:
----------------
The Content-Type header delivered with my default character set
attached ("utf-8"):
Content-Type: text/plain;charset=utf-8
Actual result:
--------------
Becuase the length is overstated by one, there is an extra character
attached to the end of the Content-Type header. Running IIS CGI this
character is an ascii-Z and IIS reports "not all headers returned."
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27687&edit=1