php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5333 Seems like a numeric overflow
Submitted: 2000-07-02 23:25 UTC Modified: 2000-07-03 11:38 UTC
From: wieschal at informatik dot uni-tuebingen dot de Assigned:
Status: Closed Package: Other
PHP Version: 4.0 Release Candidate 2 OS: Redhat 6.0 german (Intel Pentium
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: wieschal at informatik dot uni-tuebingen dot de
New email:
PHP Version: OS:

 

 [2000-07-02 23:25 UTC] wieschal at informatik dot uni-tuebingen dot de
Hi!

I'm writing a shop-solution for a company.
One rule in this company is: All customers must be at least 18 years old.
So I wrote a script with does the following:
Get the bithdate and calculate the number of seconds s
Get the curent date (in seconds since the Unix Epoch), substract 568036800 (on about 18 years in seconds).
If the bithday in seconds is greater than current date minus 18 years (both in seconds) the customer is not 18 years old.

Sorry for the long introduction, here's the bug:
If I use dates in the area June 1914 and older my script allways says that the customer is too YOUNG!

You can test it with the 2 files attached to this report:

a.html
======
<FORM ACTION="a.phtml" METHOD=POST>
Tag: <INPUT TYPE=text name="day"><BR>
Monat: <INPUT TYPE=text name="month"><BR>
Jahr:<INPUT TYPE=text name="year"><BR>
<INPUT TYPE=submit>

</FORM>

a.phtml
=======
<?
	$check_date = mktime(0, 0, 0, $month, $day, $year);
	print "Checkdate: $check_date<P>\n";
	print "date(U): " . date("U") . "<P>\n";
	$a = date("U") - 568036800;
	print "a: $a<P>\n";
	if ($check_date > $a) print "to young"; else print "old enough";
	$b = $a - $check_date;
	print "<P>\$a - \$checkdate: $b";
?>
E.g.:
Given bithdate is (today: 01. July 2000) 15.6.1914
Then you'll get the following:
Checkdate: -1752973200

date(U): 962487005

a: 394450205

old enough

$a - $checkdate: 2147423405

Given bithday is 14.6.1914
Checkdate: -1753059600

date(U): 962487054

a: 394450254

zu jung

$a - $checkdate: -2147457442

You can see that the 32-bit integer (signed) is overflowing.

Ciao,
Steffen

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-03 11:38 UTC] stas at cvs dot php dot net
I do not see how PHP can do anything about it, short of writing own Unix with more bits in time value.
You'll need to seek some other algorithm to calculate dates.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 18:01:31 2024 UTC