PHP 4.0 Bug #5333: Seems like a numeric overflow

From: Date: Sun, 02 Jul 2000 21:25:51 +0000
Subject: PHP 4.0 Bug #5333: Seems like a numeric overflow
Groups: php.dev 
Request: Send a blank email to php-dev+get-23174@lists.php.net to get a copy of this message
From: wieschal@informatik.uni-tuebingen.de Operating system: Redhat 6.0 german (Intel Pentium) PHP version: 4.0 Release Candidate 2 PHP Bug Type: Other Bug description: Seems like a numeric overflow 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

« previous php.dev (#23174) next »