-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH-10908: Bus error with PDO Firebird on RPI with 64 bit kernel a…
…nd 32 bit userland The alignment of sqldata is in most cases only the basic alignment, so the code type-puns it to a larger type, it *can* crash due to the misaligned access. This is only an issue for types > 4 bytes because every sensible system requires an alignment of at least 4 bytes for allocated data. Even though this patch uses memcpy, the compiler is smart enough to optimise it to something more efficient, especially on x86. This is just the usual approach to solve these alignment problems. Actually, unaligned memory access is undefined behaviour, so even on x86 platforms, where the bug doesn't cause a crash, this can be problematic. Furthermore, even though the issue talks about a 64-bit kernel and 32-bit userspace, this doesn't necessarily need to be the case to trigger this crash. Test was Co-authored-by: rvk01 Closes GH-10920.
- Loading branch information
Showing
3 changed files
with
211 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
--TEST-- | ||
GH-10908 (Bus error with PDO Firebird on RPI with 64 bit kernel and 32 bit userland) | ||
--EXTENSIONS-- | ||
pdo_firebird | ||
--SKIPIF-- | ||
<?php require('skipif.inc'); ?> | ||
--ENV-- | ||
LSAN_OPTIONS=detect_leaks=0 | ||
--FILE-- | ||
<?php | ||
|
||
require("testdb.inc"); | ||
|
||
$sql = <<<EOT | ||
CREATE TABLE gh10908( | ||
ID BIGINT NOT NULL, | ||
CODE VARCHAR(60) NOT NULL, | ||
NUM NUMERIC(18, 3), | ||
DBL DOUBLE PRECISION, | ||
FLT FLOAT, | ||
TS TIMESTAMP, | ||
MYDATE DATE, | ||
MYTIME TIME, | ||
MYBLOB BLOB, | ||
MYBINARY BINARY(2), | ||
MYVARBINARY VARBINARY(2), | ||
MYSMALLINT SMALLINT, | ||
MYINT INT, | ||
MYCHAR CHAR(10), | ||
MYVARCHAR VARCHAR(5), | ||
MYBOOL BOOLEAN | ||
); | ||
EOT; | ||
$dbh->exec($sql); | ||
$dbh->exec("INSERT INTO gh10908 VALUES(1, 'ABC', 12.34, 1.0, 2.0, '2023-03-24 17:39', '2023-03-24', '17:39', 'abcdefg', 'ab', 'a', 32767, 200000, 'azertyuiop', 'ab', false);"); | ||
|
||
function query_and_dump($dbh, $sql) { | ||
foreach ($dbh->query($sql) as $row) { | ||
print_r($row); | ||
print("\n"); | ||
} | ||
} | ||
|
||
query_and_dump($dbh, "SELECT CODE FROM gh10908"); // works fine | ||
query_and_dump($dbh, "SELECT ID FROM gh10908"); // Used to "bus error" | ||
query_and_dump($dbh, "SELECT NUM FROM gh10908"); // Used to "bus error" | ||
query_and_dump($dbh, "SELECT DBL FROM gh10908"); // Used to "bus error" | ||
query_and_dump($dbh, "SELECT TS FROM gh10908"); // Used to "bus error" | ||
query_and_dump($dbh, "SELECT MYBLOB FROM gh10908"); // Used to "bus error" | ||
query_and_dump($dbh, "SELECT * FROM gh10908"); // Used to "bus error" | ||
|
||
query_and_dump($dbh, "SELECT CAST(NUM AS NUMERIC(9, 3)) FROM gh10908"); // works fine | ||
query_and_dump($dbh, "SELECT CAST(ID AS INTEGER) FROM gh10908"); // works fine | ||
query_and_dump($dbh, "SELECT CAST(ID AS BIGINT) FROM gh10908"); // Used to "bus error" | ||
|
||
echo "Did not crash\n"; | ||
|
||
?> | ||
--CLEAN-- | ||
<?php | ||
require 'testdb.inc'; | ||
$dbh->exec("DROP TABLE gh10908"); | ||
?> | ||
--EXPECT-- | ||
Array | ||
( | ||
[CODE] => ABC | ||
[0] => ABC | ||
) | ||
|
||
Array | ||
( | ||
[ID] => 1 | ||
[0] => 1 | ||
) | ||
|
||
Array | ||
( | ||
[NUM] => 12.340 | ||
[0] => 12.340 | ||
) | ||
|
||
Array | ||
( | ||
[DBL] => 1.000000 | ||
[0] => 1.000000 | ||
) | ||
|
||
Array | ||
( | ||
[TS] => 2023-03-24 17:39:00 | ||
[0] => 2023-03-24 17:39:00 | ||
) | ||
|
||
Array | ||
( | ||
[MYBLOB] => abcdefg | ||
[0] => abcdefg | ||
) | ||
|
||
Array | ||
( | ||
[ID] => 1 | ||
[0] => 1 | ||
[CODE] => ABC | ||
[1] => ABC | ||
[NUM] => 12.340 | ||
[2] => 12.340 | ||
[DBL] => 1.000000 | ||
[3] => 1.000000 | ||
[FLT] => 2.000000 | ||
[4] => 2.000000 | ||
[TS] => 2023-03-24 17:39:00 | ||
[5] => 2023-03-24 17:39:00 | ||
[MYDATE] => 2023-03-24 | ||
[6] => 2023-03-24 | ||
[MYTIME] => 17:39:00 | ||
[7] => 17:39:00 | ||
[MYBLOB] => abcdefg | ||
[8] => abcdefg | ||
[MYBINARY] => ab | ||
[9] => ab | ||
[MYVARBINARY] => a | ||
[10] => a | ||
[MYSMALLINT] => 32767 | ||
[11] => 32767 | ||
[MYINT] => 200000 | ||
[12] => 200000 | ||
[MYCHAR] => azertyuiop | ||
[13] => azertyuiop | ||
[MYVARCHAR] => ab | ||
[14] => ab | ||
[MYBOOL] => | ||
[15] => | ||
) | ||
|
||
Array | ||
( | ||
[CAST] => 12.340 | ||
[0] => 12.340 | ||
) | ||
|
||
Array | ||
( | ||
[CAST] => 1 | ||
[0] => 1 | ||
) | ||
|
||
Array | ||
( | ||
[CAST] => 1 | ||
[0] => 1 | ||
) | ||
|
||
Did not crash |