Bug #73333 [NEW]: 2147483647 is fetched as string
| From: | cmb@php.net | Date: | Mon, 17 Oct 2016 14:20:06 +0000 |
| Subject: | Bug #73333 [NEW]: 2147483647 is fetched as string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-204868@lists.php.net to get a copy of this message | ||
From: cmb
Operating system: *
PHP version: 5.6.27
Package: SQLite related
Bug Type: Bug
Bug description:2147483647 is fetched as string
Description:
------------
ext/sqlite3 fetches integers greater than or equal to 2147483647
as strings. Even for 32bit PHP 2147483647 should be returned as
int; for 64bit PHP the supported range should be larger, of
course.
The culprit is sqlite_value_to_zval()[1] where comparisons are
made for >= INT_MAX (and <= INT_MIN), what should actually be
> ZEND_LONG_MAX (and < ZEND_LONG_MIN).
[1]
<https://github.com/php/php-src/blob/PHP-5.6.27/ext/sqlite3/sqlite3.c#L597>
Test script:
---------------
<?php
$db = new SQLite3(':memory:');
$db->exec('CREATE TABLE foo (bar INT)');
$stmt = $db->prepare('INSERT INTO foo VALUES (?)');
foreach ([-2147483648, -2147483647, 2147483646, 2147483647] as $num) {
$stmt->bindValue(1, $num, SQLITE3_INTEGER);
$stmt->execute();
}
$res = $db->query('SELECT bar FROM foo');
while (($row = $res->fetchArray(SQLITE3_ASSOC)) !== false) {
var_dump($row);
}
Expected result:
----------------
array(1) {
["bar"]=>
int(-2147483648)
}
array(1) {
["bar"]=>
int(-2147483647)
}
array(1) {
["bar"]=>
int(2147483646)
}
array(1) {
["bar"]=>
int(2147483647)
}
Actual result:
--------------
array(1) {
["bar"]=>
string(11) "-2147483648"
}
array(1) {
["bar"]=>
int(-2147483647)
}
array(1) {
["bar"]=>
int(2147483646)
}
array(1) {
["bar"]=>
string(10) "2147483647"
}
--
Edit bug report at https://bugs.php.net/bug.php?id=73333&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73333&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73333&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73333&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73333&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73333&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73333&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73333&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73333&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73333&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73333&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73333&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73333&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73333&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73333&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73333&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73333&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73333&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73333&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73333&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73333&r=mysqlcfg