From:             ahar...@php.net
Operating system: Linux (Ubuntu 9.04)
PHP version:      5.3SVN-2009-09-18 (SVN)
PHP Bug Type:     Date/time related
Bug description:  date_format buffer not long enough for >4 digit years

Description:
------------
The buffer allocated within date_format() isn't long enough for RFC 2822
formatted dates (format string 'r') when the year requires five or more
characters to be represented, which causes the output to be truncated. ISO
8601 dates ('c') are also affected, but only in the absolute extreme case,
as demonstrated below.

The naïve approach is obviously to extend the buffer size, and the patch
(against the current PHP_5_3 checkout) at
http://www.adamharvey.name/stuff/date-format-buffer.patch extends it far
enough to cover all possible contingencies on common platforms -- since
date_format() casts the year to a signed int when it calls slprintf(), the
longest possible value that needs to be catered for in the year field is
-2147483648 on any platform where int is 32 bit, which is pretty much all
of them.

Reproduce code:
---------------
<?php
$date = new DateTime('-1500-01-01');
var_dump($date->format('r'));

$date->setDate(pow(2, 31), 1, 1);
var_dump($date->format('r'));
var_dump($date->format('c'));
?>

Expected result:
----------------
string(32) "Sat, 01 Jan -1500 00:00:00 +0800"
string(38) "Wed, 01 Jan -2147483648 00:00:00 +0800"
string(32) "-2147483648-01-01T00:00:00+08:00"

Actual result:
--------------
string(31) "Sat, 01 Jan -1500 00:00:00 +080"
string(31) "Wed, 01 Jan -2147483648 00:00:0"
string(31) "-2147483648-01-01T00:00:00+08:0"

-- 
Edit bug report at http://bugs.php.net/?id=49585&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49585&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49585&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49585&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49585&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49585&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49585&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49585&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49585&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49585&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49585&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49585&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49585&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49585&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49585&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49585&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49585&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49585&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49585&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49585&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49585&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49585&r=mysqlcfg

Reply via email to