Skip to content

Commit 3da1aa6

Browse files
committed
PHPC-616: Document and array visitors should throw for corrupt BSON
1 parent e9679a4 commit 3da1aa6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/bson.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ bool php_phongo_bson_visit_document(const bson_iter_t *iter ARG_UNUSED, const ch
655655
* visitor. Free state.zchild, which we just initialized, and return
656656
* true to stop iteration for our parent context. */
657657
zval_ptr_dtor(&state.zchild);
658+
return true;
658659
}
659660
}
660661

@@ -735,6 +736,7 @@ bool php_phongo_bson_visit_array(const bson_iter_t *iter ARG_UNUSED, const char
735736
* visitor. Free state.zchild, which we just initialized, and return
736737
* true to stop iteration for our parent context. */
737738
zval_ptr_dtor(&state.zchild);
739+
return true;
738740
}
739741

740742
}

tests/bson/bson-toPHP_error-004.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ require_once __DIR__ . "/../utils/basic.inc";
99
$tests = array(
1010
// Invalid UTF-8 character in root document's field name
1111
str_replace('INVALID!', "INVALID\xFE", fromPHP(['INVALID!' => 'bar'])),
12+
// Invalid UTF-8 character in embedded document's field name
13+
str_replace('INVALID!', "INVALID\xFE", fromPHP(['foo' => ['INVALID!' => 'bar']])),
14+
// Invalid UTF-8 character in string within array field
15+
str_replace('INVALID!', "INVALID\xFE", fromPHP(['foo' => ['INVALID!']])),
1216
/* Note: we don't use a three-character string in the underflow case, as
1317
* the 4-byte string length and payload (i.e. three characters + null byte)
1418
* coincidentally satisfy the expected size for an 8-byte double. We also
@@ -36,4 +40,8 @@ OK: Got MongoDB\Driver\Exception\UnexpectedValueException
3640
Could not convert BSON document to a PHP variable
3741
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
3842
Could not convert BSON document to a PHP variable
43+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
44+
Could not convert BSON document to a PHP variable
45+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
46+
Could not convert BSON document to a PHP variable
3947
===DONE===

0 commit comments

Comments
 (0)