Skip to content

Commit 5fd5286

Browse files
committed
PHPC-889: Validate Javascript scope on BSON decoding
1 parent 4d58b2c commit 5fd5286

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

scripts/convert-bson-corpus-tests.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
'Int64 type: -1' => 'PHP encodes integers as 32-bit if range allows',
99
'Int64 type: 0' => 'PHP encodes integers as 32-bit if range allows',
1010
'Int64 type: 1' => 'PHP encodes integers as 32-bit if range allows',
11-
'Javascript Code with Scope: bad scope doc (field has bad string length)' => 'Depends on PHPC-889',
1211
'Javascript Code with Scope: Unicode and embedded null in code string, empty scope' => 'Embedded null in code string is not supported in libbson (CDRIVER-1879)',
1312
'Multiple types within the same document: All BSON types' => 'PHP encodes integers as 32-bit if range allows',
1413
'Top-level document validity: Bad $date (number, not string or hash)' => 'Legacy extended JSON $date syntax uses numbers (CDRIVER-2223)',

src/bson.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,15 @@ static void php_phongo_bson_new_javascript_from_javascript_and_scope(zval* objec
615615
intern->code = estrndup(code, code_len);
616616
intern->code_len = code_len;
617617
intern->scope = scope ? bson_copy(scope) : NULL;
618+
619+
if (scope) {
620+
php_phongo_bson_state state;
621+
622+
PHONGO_BSON_INIT_STATE(state);
623+
624+
php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state);
625+
zval_ptr_dtor(&state.zchild);
626+
}
618627
} /* }}} */
619628

620629
static void php_phongo_bson_new_javascript_from_javascript(zval* object, const char* code, size_t code_len TSRMLS_DC) /* {{{ */

tests/bson-corpus/code_w_scope-decodeError-011.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Javascript Code with Scope: bad scope doc (field has bad string length)
3-
--XFAIL--
4-
Depends on PHPC-889
53
--DESCRIPTION--
64
Generated by scripts/convert-bson-corpus-tests.php
75

0 commit comments

Comments
 (0)