mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
- Reverted previous fix for bug #46274 and properly fixed it
- Fixed bug #48060 # Also added tests for pdo_oci as it's the only other driver currently # using streams: no regression found
This commit is contained in:
parent
763248af68
commit
7db1207d47
5 changed files with 167 additions and 8 deletions
|
@ -583,6 +583,7 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *typ
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
ZVAL_NULL(dest);
|
ZVAL_NULL(dest);
|
||||||
} else if (value_len == 0) {
|
} else if (value_len == 0) {
|
||||||
|
/* Warning, empty strings need to be passed as stream */
|
||||||
if (stmt->dbh->stringify || new_type == PDO_PARAM_STR) {
|
if (stmt->dbh->stringify || new_type == PDO_PARAM_STR) {
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
71
ext/pdo_oci/tests/bug46274.phpt
Normal file
71
ext/pdo_oci/tests/bug46274.phpt
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and blob)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci'))
|
||||||
|
die('skip not loaded');
|
||||||
|
require dirname(__FILE__).'/../../pdo/tests/pdo_test.inc';
|
||||||
|
PDOTest::skip();
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require 'ext/pdo/tests/pdo_test.inc';
|
||||||
|
$db = PDOTest::test_factory('ext/pdo_oci/tests/common.phpt');
|
||||||
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
||||||
|
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$db->exec("DROP TABLE test_one_blob");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->beginTransaction();
|
||||||
|
|
||||||
|
$db->query('CREATE TABLE test_one_blob (id INT NOT NULL, blob1 BLOB)');
|
||||||
|
|
||||||
|
$stmt = $db->prepare("INSERT INTO test_one_blob (id, blob1) VALUES (:id, EMPTY_BLOB()) RETURNING blob1 INTO :foo");
|
||||||
|
|
||||||
|
$data = 'foo';
|
||||||
|
$blob = fopen('php://memory', 'a');
|
||||||
|
fwrite($blob, $data);
|
||||||
|
rewind($blob);
|
||||||
|
|
||||||
|
$id = 1;
|
||||||
|
$stmt->bindparam(':id', $id);
|
||||||
|
$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$data = '';
|
||||||
|
$blob = fopen('php://memory', 'a');
|
||||||
|
fwrite($blob, $data);
|
||||||
|
rewind($blob);
|
||||||
|
|
||||||
|
$id = 1;
|
||||||
|
$stmt->bindparam(':id', $id);
|
||||||
|
$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$res = $db->query("SELECT blob1 from test_one_blob");
|
||||||
|
// Resource
|
||||||
|
var_dump($res->fetch());
|
||||||
|
|
||||||
|
// Empty string
|
||||||
|
var_dump($res->fetch());
|
||||||
|
|
||||||
|
$db->exec("DROP TABLE test_one_blob");
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
array(2) {
|
||||||
|
["blob1"]=>
|
||||||
|
string(3) "foo"
|
||||||
|
[0]=>
|
||||||
|
string(3) "foo"
|
||||||
|
}
|
||||||
|
array(2) {
|
||||||
|
["blob1"]=>
|
||||||
|
string(0) ""
|
||||||
|
[0]=>
|
||||||
|
string(0) ""
|
||||||
|
}
|
77
ext/pdo_oci/tests/bug46274_2.phpt
Normal file
77
ext/pdo_oci/tests/bug46274_2.phpt
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #46274 (pdo_pgsql - Segfault when using PDO::ATTR_STRINGIFY_FETCHES and blob)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
if (!extension_loaded('pdo') || !extension_loaded('pdo_oci'))
|
||||||
|
die('skip not loaded');
|
||||||
|
require dirname(__FILE__).'/../../pdo/tests/pdo_test.inc';
|
||||||
|
PDOTest::skip();
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require 'ext/pdo/tests/pdo_test.inc';
|
||||||
|
$db = PDOTest::test_factory('ext/pdo_oci/tests/common.phpt');
|
||||||
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
||||||
|
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$db->exec("DROP TABLE test_one_blob");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->beginTransaction();
|
||||||
|
|
||||||
|
$db->query('CREATE TABLE test_one_blob (id INT NOT NULL, blob1 BLOB)');
|
||||||
|
|
||||||
|
$stmt = $db->prepare("INSERT INTO test_one_blob (id, blob1) VALUES (:id, EMPTY_BLOB()) RETURNING blob1 INTO :foo");
|
||||||
|
|
||||||
|
$data = 'foo';
|
||||||
|
$blob = fopen('php://memory', 'a');
|
||||||
|
fwrite($blob, $data);
|
||||||
|
rewind($blob);
|
||||||
|
|
||||||
|
$id = 1;
|
||||||
|
$stmt->bindparam(':id', $id);
|
||||||
|
$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$data = '';
|
||||||
|
$blob = fopen('php://memory', 'a');
|
||||||
|
fwrite($blob, $data);
|
||||||
|
rewind($blob);
|
||||||
|
|
||||||
|
$id = 1;
|
||||||
|
$stmt->bindparam(':id', $id);
|
||||||
|
$stmt->bindparam(':foo', $blob, PDO::PARAM_LOB);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$res = $db->query("SELECT blob1 from test_one_blob");
|
||||||
|
// Resource
|
||||||
|
var_dump($row = $res->fetch());
|
||||||
|
var_dump(fread($row[0], 1024));
|
||||||
|
fclose($row[0]);
|
||||||
|
|
||||||
|
// Empty string
|
||||||
|
var_dump($row = $res->fetch());
|
||||||
|
var_dump(fread($row[0], 1024));
|
||||||
|
fclose($row[0]);
|
||||||
|
|
||||||
|
$db->exec("DROP TABLE test_one_blob");
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
array(2) {
|
||||||
|
["blob1"]=>
|
||||||
|
resource(%d) of type (stream)
|
||||||
|
[0]=>
|
||||||
|
resource(%d) of type (stream)
|
||||||
|
}
|
||||||
|
string(3) "foo"
|
||||||
|
array(2) {
|
||||||
|
["blob1"]=>
|
||||||
|
resource(%d) of type (stream)
|
||||||
|
[0]=>
|
||||||
|
resource(%d) of type (stream)
|
||||||
|
}
|
||||||
|
string(0) ""
|
|
@ -619,9 +619,15 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
*ptr = php_pdo_pgsql_unescape_bytea(*ptr, &tmp_len);
|
*ptr = php_pdo_pgsql_unescape_bytea(*ptr, &tmp_len);
|
||||||
|
if (!tmp_len) {
|
||||||
|
/* Empty string, return as empty stream */
|
||||||
|
*ptr = (char *)php_stream_memory_open(TEMP_STREAM_READONLY, "", 0);
|
||||||
|
*len = 0;
|
||||||
|
} else {
|
||||||
*len = tmp_len;
|
*len = tmp_len;
|
||||||
*caller_frees = 1;
|
*caller_frees = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PDO_PARAM_NULL:
|
case PDO_PARAM_NULL:
|
||||||
case PDO_PARAM_STR:
|
case PDO_PARAM_STR:
|
||||||
|
|
|
@ -47,11 +47,13 @@ $res = $db->query("SELECT blob1 from test_one_blob");
|
||||||
var_dump($x = $res->fetch());
|
var_dump($x = $res->fetch());
|
||||||
var_dump(fread($x['blob1'], 10));
|
var_dump(fread($x['blob1'], 10));
|
||||||
|
|
||||||
// Empty string
|
// Resource
|
||||||
var_dump($res->fetch());
|
var_dump($res->fetch());
|
||||||
|
var_dump(fread($x['blob1'], 10));
|
||||||
|
|
||||||
// Empty string
|
// Resource
|
||||||
var_dump($res->fetch());
|
var_dump($res->fetch());
|
||||||
|
var_dump(fread($x['blob1'], 10));
|
||||||
|
|
||||||
// NULL
|
// NULL
|
||||||
var_dump($res->fetch());
|
var_dump($res->fetch());
|
||||||
|
@ -69,16 +71,18 @@ array(2) {
|
||||||
string(3) "foo"
|
string(3) "foo"
|
||||||
array(2) {
|
array(2) {
|
||||||
["blob1"]=>
|
["blob1"]=>
|
||||||
string(0) ""
|
resource(%d) of type (stream)
|
||||||
[0]=>
|
[0]=>
|
||||||
string(0) ""
|
resource(%d) of type (stream)
|
||||||
}
|
}
|
||||||
|
string(0) ""
|
||||||
array(2) {
|
array(2) {
|
||||||
["blob1"]=>
|
["blob1"]=>
|
||||||
string(0) ""
|
resource(%d) of type (stream)
|
||||||
[0]=>
|
[0]=>
|
||||||
string(0) ""
|
resource(%d) of type (stream)
|
||||||
}
|
}
|
||||||
|
string(0) ""
|
||||||
array(2) {
|
array(2) {
|
||||||
["blob1"]=>
|
["blob1"]=>
|
||||||
NULL
|
NULL
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue