php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49973 Filter PHPT fails on 64-bit. PHPT testcase incorrectly uses ~(PHPT_INT_MAX-1).
Submitted: 2009-10-23 15:19 UTC Modified: 2009-11-30 19:52 UTC
From: php dot vope at gishpuppy dot com Assigned:
Status: Closed Package: Filter related
PHP Version: 5.2.11 OS: Linux x86 64-bit
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php dot vope at gishpuppy dot com
New email:
PHP Version: OS:

 

 [2009-10-23 15:19 UTC] php dot vope at gishpuppy dot com
Description:
------------
The PHPT test ext\filter\046.phpt fails when run on a 64-bit system.

The problem is likely to be that ~(PHP_INT_MAX)-1 is not sufficient to create an underflow on 64-bit. This is because a float on 64-bit has less bits than an integer ( since it needs some for the exponent ).

The test would pass if ~(PHP_INT_MAX)-2000 was used instead.

On 64-bit
~(PHP_INT_MAX)-2000 = float(-9223372036854777856)
which would be enough of a difference to make the test valid.

Thanks in advance, Tim Preece

Reproduce code:
---------------
From http://svn.php.net/repository/php/php-src/branches/PHP_5_2/ext/filter/tests/046.phpt.

--TEST--
Integer overflow
--SKIPIF--
<?php if (!extension_loaded("filter")) die("skip"); ?>
--FILE--
<?php
$s = sprintf("%d", PHP_INT_MAX);
var_dump(is_long(filter_var($s, FILTER_VALIDATE_INT)));

$s = sprintf("%.0f", PHP_INT_MAX+1);
var_dump(filter_var($s, FILTER_VALIDATE_INT));

$s = sprintf("%d", -PHP_INT_MAX);
var_dump(is_long(filter_var($s, FILTER_VALIDATE_INT)));

$s = sprintf("%.0f", ~(PHP_INT_MAX)-1);
var_dump(filter_var($s, FILTER_VALIDATE_INT));
?>
--EXPECT--
bool(true)
bool(false)
bool(true)
bool(false)

Expected result:
----------------
--EXPECT--
bool(true)
bool(false)
bool(true)
bool(false)

Actual result:
--------------
On a 64-bit system:

bool(true)
bool(false)
bool(true)
int(-9223372036854775808)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-30 19:52 UTC] jani@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 15:01:32 2024 UTC