Skip to content

Commit 93bd10b

Browse files
authored
PHPC-1897: Test serialization of BSON with embedded null bytes in strings (#1255)
* BSON corpus prose tests for null bytes For tests that already existed we just add a reference to the prose test * BSON corpus tests for null bytes Synced with mongodb/specifications@c64fc79 This sync also removes some old DBRef tests, which should have been removed in 6929bcb. * Bump libmongoc to 1.19.1 to pull in changes from CDRIVER-4083
1 parent a4740e8 commit 93bd10b

15 files changed

+115
-8
lines changed

src/LIBMONGOC_VERSION_CURRENT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.19.0
1+
1.19.1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Document type (sub-documents): Null byte in sub-document key
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/basic.inc';
11+
12+
$bson = hex2bin('150000000378000D00000010610000010000000000');
13+
14+
throws(function() use ($bson) {
15+
var_dump(toPHP($bson));
16+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECT--
22+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
23+
===DONE===

tests/bson-corpus/regex-decodeError-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Regular Expression type: embedded null in pattern
2+
Regular Expression type: Null byte in pattern string
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

tests/bson-corpus/regex-decodeError-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Regular Expression type: embedded null in flags
2+
Regular Expression type: Null byte in flags string
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Top-level document validity: Null byte in document key
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/basic.inc';
11+
12+
$bson = hex2bin('0D000000107800000100000000');
13+
14+
throws(function() use ($bson) {
15+
var_dump(toPHP($bson));
16+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECT--
22+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
23+
===DONE===

tests/bson-corpus/top-parseError-041.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Top-level document validity: Bad $maxKey (extra field)
2+
Top-level document validity: Null byte in document key
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

@@ -10,7 +10,7 @@ DO NOT EDIT THIS FILE
1010
require_once __DIR__ . '/../utils/basic.inc';
1111

1212
throws(function() {
13-
fromJSON('{"a" : {"$maxKey" : 1, "unrelated": true}}');
13+
fromJSON('{"a\\u0000": 1 }');
1414
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
1515

1616
?>

tests/bson-corpus/top-parseError-042.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Top-level document validity: Bad DBpointer (extra field)
2+
Top-level document validity: Null byte in sub-document key
33
--DESCRIPTION--
44
Generated by scripts/convert-bson-corpus-tests.php
55

@@ -10,7 +10,7 @@ DO NOT EDIT THIS FILE
1010
require_once __DIR__ . '/../utils/basic.inc';
1111

1212
throws(function() {
13-
fromJSON('{"a": {"$dbPointer": {"a": {"$numberInt": "1"}, "$id": {"$oid": "56e1fc72e0c917e9c4714161"}, "c": {"$numberInt": "2"}, "$ref": "b"}}}');
13+
fromJSON('{"a" : {"b\\u0000": 1 }}');
1414
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
1515

1616
?>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Top-level document validity: Null byte in $regularExpression pattern
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/basic.inc';
11+
12+
throws(function() {
13+
fromJSON('{"a" : {"$regularExpression" : { "pattern": "b\\u0000", "options" : "i"}}}');
14+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
15+
16+
?>
17+
===DONE===
18+
<?php exit(0); ?>
19+
--EXPECT--
20+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
21+
===DONE===
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Top-level document validity: Null byte in $regularExpression options
3+
--DESCRIPTION--
4+
Generated by scripts/convert-bson-corpus-tests.php
5+
6+
DO NOT EDIT THIS FILE
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/basic.inc';
11+
12+
throws(function() {
13+
fromJSON('{"a" : {"$regularExpression" : { "pattern": "b", "options" : "i\\u0000"}}}');
14+
}, 'MongoDB\Driver\Exception\UnexpectedValueException');
15+
16+
?>
17+
===DONE===
18+
<?php exit(0); ?>
19+
--EXPECT--
20+
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
21+
===DONE===

0 commit comments

Comments
 (0)