diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2016-10-17 16:58:49 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2016-10-17 23:34:41 +0200 |
commit | 86e603a664afdc3a12ead0eaca5d37fa8a379381 (patch) | |
tree | feea44fc88e7ba7aa6b5273d9bd81f0632709e2a | |
parent | e1f5b6d8dfe1543205d5b45d3dcf1d34f5e2e420 (diff) | |
download | php-git-86e603a664afdc3a12ead0eaca5d37fa8a379381.tar.gz |
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>.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | ext/sqlite3/sqlite3.c | 11 | ||||
-rw-r--r-- | ext/sqlite3/tests/bug63921-32bit.phpt | 2 | ||||
-rw-r--r-- | ext/sqlite3/tests/bug63921-64bit.phpt | 2 | ||||
-rw-r--r-- | ext/sqlite3/tests/bug73333.phpt | 26 |
5 files changed, 40 insertions, 4 deletions
@@ -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 54ec73d6ac..80d6b897f1 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 8c1c6b9414..d2cc7b2002 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 8e821fd2d0..d6c539e185 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 0000000000..7315751810 --- /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===
|