com php-src: Fix #73333: 2147483647 is fetched as string: NEWS ext/sqlite3/sqlite3.c ext/sqlite3/tests/bug63921-32bit.phpt
ext/sqlite3/tests/bug63921-64bit.phpt ext/sqlite3/tests/bug73333.phpt

From: Date: Mon, 17 Oct 2016 21:34:41 +0000
Subject: com php-src: Fix #73333: 2147483647 is fetched as string: NEWS ext/sqlite3/sqlite3.c ext/sqlite3/tests/bug63921-32bit.phpt
ext/sqlite3/tests/bug63921-64bit.phpt ext/sqlite3/tests/bug73333.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-95177@lists.php.net to get a copy of this message
Commit: 86e603a664afdc3a12ead0eaca5d37fa8a379381 Author: Christoph M. Becker <cmbecker69@gmx.de> Mon, 17 Oct 2016 16:58:49 +0200 Parents: e1f5b6d8dfe1543205d5b45d3dcf1d34f5e2e420 Branches: PHP-5.6 PHP-7..0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=86e603a664afdc3a12ead0eaca5d37fa8a379381 Log: Fix #73333: 2147483647 is fetched as string We return all integers that can be represented as such by PHP as integers, and only those that exceed the possible range as strings. On builds which represent integers with 64 bits, the range check is unnecessary and might cause code checkers to complain, so we skip this special casing via the preprocessor according to <http://git.php.net/?p=php-src.git;a=commit;h=99d087e5>. Bugs: https://bugs.php.net/73333 Changed paths: M NEWS M ext/sqlite3/sqlite3.c M ext/sqlite3/tests/bug63921-32bit.phpt M ext/sqlite3/tests/bug63921-64bit.phpt A ext/sqlite3/tests/bug73333.phpt Diff: diff --git a/NEWS b/NEWS index 26b53f7..6db7d29 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,9 @@ PHP NEWS - SOAP: . Fixed bug #73037 (SoapServer reports Bad Request when gzipped). (Anatol) +- SQLite3: + . Fixed bug #73333 (2147483647 is fetched as string). (cmb) + - Standard: . Fixed bug #73203 (passing additional_parameters causes mail to fail). (cmb) . Fixed bug #73188 (use after free in userspace streams). (Sara) diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 54ec73d..80d6b89 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -591,14 +591,21 @@ PHP_METHOD(sqlite3, query) static zval* sqlite_value_to_zval(sqlite3_stmt *stmt, int column) /* {{{ */ { zval *data; + sqlite3_int64 val; + MAKE_STD_ZVAL(data); switch (sqlite3_column_type(stmt, column)) { case SQLITE_INTEGER: - if ((sqlite3_column_int64(stmt, column)) >= INT_MAX || sqlite3_column_int64(stmt, column) <= INT_MIN) { + val = sqlite3_column_int64(stmt, column); +#if LONG_MAX <= 2147483647 + if (val > LONG_MAX || val < LONG_MIN) { ZVAL_STRINGL(data, (char *)sqlite3_column_text(stmt, column), sqlite3_column_bytes(stmt, column), 1); } else { - ZVAL_LONG(data, sqlite3_column_int64(stmt, column)); +#endif + ZVAL_LONG(data, val); +#if LONG_MAX <= 2147483647 } +#endif break; case SQLITE_FLOAT: diff --git a/ext/sqlite3/tests/bug63921-32bit.phpt b/ext/sqlite3/tests/bug63921-32bit.phpt index 8c1c6b9..d2cc7b2 100644 --- a/ext/sqlite3/tests/bug63921-32bit.phpt +++ b/ext/sqlite3/tests/bug63921-32bit.phpt @@ -24,4 +24,4 @@ var_dump($num,$result[0]); ?> --EXPECT-- int(2147483647) -string(10) "2147483647" +int(2147483647) diff --git a/ext/sqlite3/tests/bug63921-64bit.phpt b/ext/sqlite3/tests/bug63921-64bit.phpt index 8e821fd..d6c539e 100644 --- a/ext/sqlite3/tests/bug63921-64bit.phpt +++ b/ext/sqlite3/tests/bug63921-64bit.phpt @@ -24,4 +24,4 @@ var_dump($num,$result[0]); ?> --EXPECT-- int(100004313234244) -string(15) "100004313234244" +int(100004313234244) diff --git a/ext/sqlite3/tests/bug73333.phpt b/ext/sqlite3/tests/bug73333.phpt new file mode 100644 index 0000000..7315751 --- /dev/null +++ b/ext/sqlite3/tests/bug73333.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #73333 (2147483647 is fetched as string) +--SKIPIF-- +<?php +if (!extension_loaded('sqlite3')) die('skip sqlite3 extension not available'); +?> +--FILE-- +<?php +if (!defined('PHP_INT_MIN')) define('PHP_INT_MIN', -PHP_INT_MAX-1); + +$db = new SQLite3(':memory:'); +$db->exec('CREATE TABLE foo (bar INT)'); +foreach ([PHP_INT_MIN, PHP_INT_MAX] as $value) { + $db->exec("INSERT INTO foo VALUES ($value)"); +} + +$res = $db->query('SELECT bar FROM foo'); +while (($row = $res->fetchArray(SQLITE3_NUM)) !== false) { + echo gettype($row[0]), PHP_EOL; +} +?> +===DONE=== +--EXPECT-- +integer +integer +===DONE===

« previous php.cvs (#95177) next »