Skip to content

Commit bc6e7c5

Browse files
committed
Added splitting of the options array as we're modifying it, and make sure we only accept array zvals for options.
1 parent dc98d5f commit bc6e7c5

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

gridfs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ PHP_METHOD(MongoGridFS, storeBytes) {
412412
chunks = zend_read_property(mongo_ce_GridFS, getThis(), "chunks", strlen("chunks"), NOISY TSRMLS_CC);
413413
ensure_gridfs_index(&temp, chunks TSRMLS_CC);
414414

415-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|az", &bytes, &bytes_len, &extra, &options) == FAILURE) {
416-
return;
417-
}
415+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|aa/", &bytes, &bytes_len, &extra, &options) == FAILURE) {
416+
return;
417+
}
418418

419419
// file array object
420420
MAKE_STD_ZVAL(zfile);
@@ -586,9 +586,9 @@ PHP_METHOD(MongoGridFS, storeFile) {
586586

587587
ensure_gridfs_index(&temp, chunks TSRMLS_CC);
588588

589-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|az", &fh, &extra, &options) == FAILURE) {
590-
return;
591-
}
589+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|aa/", &fh, &extra, &options) == FAILURE) {
590+
return;
591+
}
592592

593593
if (Z_TYPE_P(fh) == IS_RESOURCE) {
594594
zend_rsrc_list_entry *le;

tests/bug00320-2.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ Test for bug PHP-320: GridFS transaction issues with storeBytes().
1919
echo "######################################\n";
2020
echo "# Saving files to GridFS\n";
2121
echo "######################################\n";
22+
$options = array( 'safe' => false );
2223
for ($i = 0; $i < 3; $i++) {
2324
try {
24-
$new_saved_file_object_id = $GridFS->storeBytes($temporary_file_data, array( '_id' => "file{$i}", 'filename' => '/tmp/GridFS_test.txt'));
25+
$new_saved_file_object_id = $GridFS->storeBytes($temporary_file_data, array( '_id' => "file{$i}", 'filename' => '/tmp/GridFS_test.txt'), $options);
2526
echo "[Saved file] New file id:".$new_saved_file_object_id."\n";
2627
}
2728
catch (MongoException $e) {
@@ -30,6 +31,7 @@ Test for bug PHP-320: GridFS transaction issues with storeBytes().
3031
}
3132

3233
}
34+
var_dump( $options );
3335

3436
echo "\n";
3537
echo "######################################\n";
@@ -57,6 +59,10 @@ error message: Could not store file: E11000 duplicate key error index: phpunit.f
5759
error code: 0
5860
error message: Could not store file: E11000 duplicate key error index: phpunit.fs.files.$filename_1 dup key: { : "/tmp/GridFS_test.txt" }
5961
error code: 0
62+
array(1) {
63+
["safe"]=>
64+
bool(false)
65+
}
6066
######################################
6167
# Current documents in fs.files
6268
######################################

tests/bug00320.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ Test for bug PHP-320: GridFS transaction issues with storeFile().
2121
echo "######################################\n";
2222
echo "# Saving files to GridFS\n";
2323
echo "######################################\n";
24+
$options = array( 'safe' => false );
2425
for ($i = 0; $i < 3; $i++) {
2526
try {
26-
$new_saved_file_object_id = $GridFS->storeFile($temporary_file_name, array( '_id' => "file{$i}"));
27+
$new_saved_file_object_id = $GridFS->storeFile($temporary_file_name, array( '_id' => "file{$i}"), $options);
2728
echo "[Saved file] New file id:".$new_saved_file_object_id."\n";
2829
}
2930
catch (MongoException $e) {
@@ -32,6 +33,7 @@ Test for bug PHP-320: GridFS transaction issues with storeFile().
3233
}
3334

3435
}
36+
var_dump( $options );
3537

3638
echo "\n";
3739
echo "######################################\n";
@@ -59,6 +61,10 @@ error message: Could not store file: E11000 duplicate key error index: phpunit.f
5961
error code: 0
6062
error message: Could not store file: E11000 duplicate key error index: phpunit.fs.files.$filename_1 dup key: { : "/tmp/GridFS_test.txt" }
6163
error code: 0
64+
array(1) {
65+
["safe"]=>
66+
bool(false)
67+
}
6268
######################################
6369
# Current documents in fs.files
6470
######################################

0 commit comments

Comments
 (0)