xref: /PHP-8.3/ext/pdo_pgsql/tests/bug46274.phpt (revision 4f84b159)
1--TEST--
2Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and blob)
3--EXTENSIONS--
4pdo
5pdo_pgsql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
15$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
16
17$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
18
19try {
20    @$db->query("SET bytea_output = 'escape'");
21} catch (Exception $e) {
22}
23
24$db->query('CREATE TABLE test_one_blob_46274_1 (id SERIAL NOT NULL, blob1 BYTEA)');
25
26$stmt = $db->prepare("INSERT INTO test_one_blob_46274_1 (blob1) VALUES (:foo)");
27
28$data = 'foo';
29$blob = fopen('php://memory', 'a');
30fwrite($blob, $data);
31rewind($blob);
32
33$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
34$stmt->execute();
35
36$blob = '';
37$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
38$stmt->execute();
39
40$data = '';
41$blob = fopen('php://memory', 'a');
42fwrite($blob, $data);
43rewind($blob);
44
45$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
46$stmt->execute();
47
48$blob = NULL;
49$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
50$stmt->execute();
51
52$res = $db->query("SELECT blob1 from test_one_blob_46274_1");
53// Resource
54var_dump($res->fetch());
55
56// Empty string
57var_dump($res->fetch());
58
59// Empty string
60var_dump($res->fetch());
61
62// NULL
63var_dump($res->fetch());
64?>
65--CLEAN--
66<?php
67require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
68$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
69$db->query('DROP TABLE IF EXISTS test_one_blob_46274_1');
70?>
71--EXPECT--
72array(2) {
73  ["blob1"]=>
74  string(3) "foo"
75  [0]=>
76  string(3) "foo"
77}
78array(2) {
79  ["blob1"]=>
80  string(0) ""
81  [0]=>
82  string(0) ""
83}
84array(2) {
85  ["blob1"]=>
86  string(0) ""
87  [0]=>
88  string(0) ""
89}
90array(2) {
91  ["blob1"]=>
92  NULL
93  [0]=>
94  NULL
95}
96