php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53608 mktime() produces invalid results under 64-bit
Submitted: 2010-12-24 22:19 UTC Modified: 2021-04-07 09:21 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: jer_826 at yahoo dot com Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 5.2.16 OS: Linux 2.6.35.7 x86_64
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-12-24 22:19 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-02 09:52 UTC] 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.
 [2011-01-04 07:39 UTC] aharvey@php.net
-Status: Open +Status: Verified -Package: Unknown/Other Function +Package: Date/time related
 [2011-01-04 07:39 UTC] aharvey@php.net
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?
 [2011-03-31 12:05 UTC] cataphract@php.net
I think the only reasonable fix here is to check the range of the arguments on the beginning of the function. Checking for overflow everywhere doesn't seem very handy since there are lots of places and functions (which would have to be changed to signal overflow errors) where this would have to be done.
 [2021-04-07 09:21 UTC] derick@php.net
-Status: Verified +Status: Wont fix
 [2021-04-07 09:21 UTC] derick@php.net
Adding overflow detection here would make things really cumbersome and slower, and IMO it's not worth the effort.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 23:01:29 2024 UTC