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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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 Apr 18 19:01:30 2024 UTC