php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63916 PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
Submitted: 2013-01-06 05:20 UTC Modified: 2013-01-14 17:00 UTC
From: googleguy@php.net Assigned:
Status: Closed Package: PDO related
PHP Version: 5.4.10 OS:
Private report: No CVE-ID: None
 [2013-01-06 05:20 UTC] googleguy@php.net
Description:
------------
Binding a PDO parameter with pdo_sqlite on 64bit builds with PDO::PARAM_INT 
forces the param to be cast internally to an int. This means 64bit ints will be 
cast down to 32bit ints internally even if PHP was compiled against a 64bit arch.

Test script:
---------------
$num = 100004313234244; // notice this exceeds 32 bits
$conn = new PDO('sqlite::memory:');
$conn->query('CREATE TABLE users (id INTEGER NOT NULL, num INTEGER NOT NULL, PRIMARY KEY(id))');

$stmt = $conn->prepare('insert into users (id, num) values (:id, :num)');
$stmt->bindValue(':id', 1, PDO::PARAM_INT);
$stmt->bindValue(':num', $num, PDO::PARAM_INT);
$stmt->execute();

$stmt = $conn->query('SELECT num FROM users');
$result = $stmt->fetchAll(PDO::FETCH_COLUMN);

printf("Expected: %d Received: %d\n", $num, $result[0]);

Expected result:
----------------
// expected to output
Expected: 100004313234244 Received: 100004313234244

Actual result:
--------------
// instead we get output of
Expected: 100004313234244 Received: 294714180

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-06 05:22 UTC] googleguy@php.net
-Summary: PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlie +Summary: PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
 [2013-01-06 12:57 UTC] googleguy@php.net
Because we're currently running 3 branches I've sent the PR for this to master 
and I'm asking for it to be merged into 5.3.NEXT, 5.4.NEXT, and 5.5.NEXT 
respectively to maintain consistency.

https://github.com/php/php-src/pull/253/
 [2013-01-12 22:03 UTC] googleguy@php.net
This seems to be a regression from the PHP-5.2 branch as well. After testing on PHP-
5.2,5.3,5.4,5.5,and master branches I found that the issue did not exist back in ext/sqlite2 
as string casting was done instead of using integer types. The issue probably was over looked 
when the sqlite3 driver was ported in to replace the old ext/sqlite2.

Regression results:

http://playground.sheriframadan.com/testphphL1I9j
 [2013-01-14 16:59 UTC] lstrojny@php.net
Automatic comment on behalf of lstrojny
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1e9a3ed234af443170d9ea8280a556d85299e301
Log: Fix bug #63916: PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
 [2013-01-14 16:59 UTC] lstrojny@php.net
-Status: Open +Status: Closed
 [2013-01-14 17:00 UTC] lstrojny@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.4-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Merged into 5.4, 5.5 and master
 [2013-01-14 17:00 UTC] lstrojny@php.net
-Status: Closed +Status: Feedback
 [2013-01-14 17:16 UTC] lstrojny@php.net
Automatic comment on behalf of lstrojny
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1e9a3ed234af443170d9ea8280a556d85299e301
Log: Fix bug #63916: PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
 [2013-01-14 17:16 UTC] lstrojny@php.net
-Status: Feedback +Status: Closed
 [2013-01-14 17:17 UTC] lstrojny@php.net
Automatic comment on behalf of lstrojny
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1e9a3ed234af443170d9ea8280a556d85299e301
Log: Fix bug #63916: PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
 [2014-10-07 23:20 UTC] stas@php.net
Automatic comment on behalf of lstrojny
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=1e9a3ed234af443170d9ea8280a556d85299e301
Log: Fix bug #63916: PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
 [2014-10-07 23:31 UTC] stas@php.net
Automatic comment on behalf of lstrojny
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=1e9a3ed234af443170d9ea8280a556d85299e301
Log: Fix bug #63916: PDO::PARAM_INT casts to 32bit int internally even on 64bit builds in pdo_sqlite
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC