Bug #53608 [Opn->Ver]: mktime() produces invalid results under 64-bit

From: Date: Tue, 04 Jan 2011 06:39:59 +0000
Subject: Bug #53608 [Opn->Ver]: mktime() produces invalid results under 64-bit
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-157534@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53608&edit=1

 ID:                 53608
 Updated by:         aharvey@php.net
 Reported by:        jer_826 at yahoo dot com
 Summary:            mktime() produces invalid results under 64-bit
-Status:             Open
+Status:             Verified
 Type:               Bug
-Package:            Unknown/Other Function
+Package:            Date/time related
 Operating System:   Linux 2.6.35.7  x86_64
 PHP Version:        5.2.16
 Block user comment: N
 Private report:     N

 New Comment:

Confirmed; the error handling in timelib_date_to_int() is insufficient
for platforms with 64 bit longs.

The quick and dirty fix would be to explicitly compare ts in
timelib_date_to_int() to the minimum and maximum values of a 32 bit
integer, but you'd then lose the ability to use mktime() for dates
outside the 1901-2038 range. Better would be to try to detect overflow
in timelib_update_ts(), but that's not going to be foolproof either.

I don't have any particularly strong feelings on this one, or even
whether it's worth trying to handle. Derick?


Previous Comments:
------------------------------------------------------------------------
[2011-01-02 09:52:16] brad at njoe dot com

Confirmed on Ubuntu 10.10 (Linux 2.6.35-24-server x86_64). Also tested a
Win32 
build and all three var_dumps() show "bool(false)" as
expected/documented.

------------------------------------------------------------------------
[2010-12-24 22:19:04] jer_826 at yahoo dot com

Description:
------------
It appears that when the PHP binary was compiled against 64-bit
libraries,  
mktime() seems to only do minimal error checking of parms. After some
additional 
testing, if found the following results:
PHP Code:
$t=mktime(0,0,0,12,3,292277026596); 
var_dump($t); 

$t=mktime(0,0,0,12,3,292277026597); 
var_dump($t); 

$t=mktime(900000000000,900000000000,900000000000,900000000000,900000000000,90000
0000000); 

var_dump($t); 
int(9223372036854655200)
int(-9223372036823360416) 
int(-6044405109589065632)

It appears that once the parm value exceeds the value limit of a long
var, the 
function returns a negative value. No warnings are produced. Instead of

returning FALSE for an error, the function just returns an invalid
result.

Some additional info here: http://phpbuilder.com/board/showthread.php?
p=10971046#post10971046

Test script:
---------------
$t=mktime(0,0,0,12,3,292277026596); 
var_dump($t); 

$t=mktime(0,0,0,12,3,292277026597); 
var_dump($t); 

$t=mktime(900000000000,900000000000,900000000000,900000000000,900000000000,900000000000);


var_dump($t); 
int(9223372036854655200)
int(-9223372036823360416) 
int(-6044405109589065632)

Expected result:
----------------
Return FALSE if parms are invalid.

Actual result:
--------------
Invalid values. Does not return FALSE.


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53608&edit=1


Thread (6 messages)

« previous php.bugs (#157534) next »