#27687 [NEW]: Bug Adding Default Charset to "text/*" Content-Type Header

From: Date: Thu, 25 Mar 2004 04:13:30 +0000
Subject: #27687 [NEW]: Bug Adding Default Charset to "text/*" Content-Type Header
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-56788@lists.php.net to get a copy of this message
From: msisolak at yahoo dot com Operating system: Windows 2000 PHP version: 5.0.0RC1 PHP Bug Type: Unknown/Other Function Bug description: Bug Adding Default Charset to "text/*" Content-Type Header 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 bug report at http://bugs.php.net/?id=27687&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27687&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27687&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=27687&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=27687&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=27687&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=27687&r=needscript Try newer version: http://bugs.php.net/fix.php?id=27687&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=27687&r=support Expected behavior: http://bugs.php.net/fix.php?id=27687&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=27687&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=27687&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=27687&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27687&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=27687&r=dst IIS Stability: http://bugs.php.net/fix.php?id=27687&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=27687&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=27687&r=float

« previous php.bugs (#56788) next »