|
| 1 | +--TEST-- |
| 2 | +GH-25006 (PDO_Firebird::getColumnMeta() reads out of bounds for an out-of-range column index) |
| 3 | +--EXTENSIONS-- |
| 4 | +pdo_firebird |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +require 'skipif.inc'; |
| 8 | +?> |
| 9 | +--XLEAK-- |
| 10 | +A bug in firebird causes a memory leak when calling `isc_attach_database()`. |
| 11 | +See https://github.com/FirebirdSQL/firebird/issues/7849 |
| 12 | +--FILE-- |
| 13 | +<?php |
| 14 | +require 'testdb.inc'; |
| 15 | + |
| 16 | +$dbh = getDbConnection(); |
| 17 | +$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 18 | + |
| 19 | +$stmt = $dbh->prepare('SELECT 1 AS one, 2 AS two FROM RDB$DATABASE'); |
| 20 | + |
| 21 | +echo "before execute: "; |
| 22 | +try { |
| 23 | + var_dump($stmt->getColumnMeta(2)); |
| 24 | +} catch (Throwable $e) { |
| 25 | + echo $e::class, ': ', $e->getMessage(), "\n"; |
| 26 | +} |
| 27 | + |
| 28 | +$stmt->execute(); |
| 29 | + |
| 30 | +echo "column 0: "; |
| 31 | +$meta = $stmt->getColumnMeta(0); |
| 32 | +echo $meta['name'], ' ', $meta['pdo_type'], "\n"; |
| 33 | + |
| 34 | +echo "column 1: "; |
| 35 | +$meta = $stmt->getColumnMeta(1); |
| 36 | +echo $meta['name'], ' ', $meta['pdo_type'], "\n"; |
| 37 | + |
| 38 | +foreach ([2, 1000000] as $col) { |
| 39 | + echo "column $col: "; |
| 40 | + try { |
| 41 | + var_dump($stmt->getColumnMeta($col)); |
| 42 | + } catch (Throwable $e) { |
| 43 | + echo $e::class, ': ', $e->getMessage(), "\n"; |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +echo "no output columns: "; |
| 48 | +$empty = $dbh->prepare('EXECUTE BLOCK AS BEGIN END'); |
| 49 | +echo $empty->columnCount(), ' '; |
| 50 | +try { |
| 51 | + var_dump($empty->getColumnMeta(0)); |
| 52 | +} catch (Throwable $e) { |
| 53 | + echo $e::class, ': ', $e->getMessage(), "\n"; |
| 54 | +} |
| 55 | + |
| 56 | +echo "negative: "; |
| 57 | +try { |
| 58 | + var_dump($stmt->getColumnMeta(-1)); |
| 59 | +} catch (Throwable $e) { |
| 60 | + echo $e::class, ': ', $e->getMessage(), "\n"; |
| 61 | +} |
| 62 | + |
| 63 | +echo "done\n"; |
| 64 | +?> |
| 65 | +--EXPECT-- |
| 66 | +before execute: PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index |
| 67 | +column 0: ONE 1 |
| 68 | +column 1: TWO 1 |
| 69 | +column 2: PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index |
| 70 | +column 1000000: PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index |
| 71 | +no output columns: 0 PDOException: SQLSTATE[07009]: Invalid descriptor index: invalid column index |
| 72 | +negative: ValueError: PDOStatement::getColumnMeta(): Argument #1 ($column) must be greater than or equal to 0 |
| 73 | +done |
0 commit comments