Skip to content

Commit 82de814

Browse files
committed
PHPC-1266: Empty deeply nested BSON document causes unallocated memory writes
1 parent 5c4b608 commit 82de814

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/bson.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ bool php_phongo_field_path_push(php_phongo_field_path* field_path, const char* e
161161

162162
bool php_phongo_field_path_pop(php_phongo_field_path* field_path)
163163
{
164+
php_phongo_field_path_ensure_allocation(field_path, field_path->size);
165+
164166
field_path->elements[field_path->size] = NULL;
165167
field_path->element_types[field_path->size] = PHONGO_FIELD_PATH_ITEM_NONE;
166168

tests/bson/bug1266.phpt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--TEST--
2+
Test for PHPC-1266: Empty deeply nested BSON document causes unallocated memory writes
3+
--FILE--
4+
<?php
5+
$a = <<<ENDJSON
6+
{
7+
"value" : {
8+
"payload" : {
9+
"PayloadMasterDataMeteringPointPartyEvent" : {
10+
"MeteringPointPartyDetailMeteringPointPartyCharacteristic" : {
11+
"AdministrativePartyMPAdministrativeParty" : [
12+
{
13+
"AdministrativePartyAddressLocationAddress" : {
14+
"StreetCode" : {
15+
}
16+
}
17+
}
18+
]
19+
}
20+
}
21+
}
22+
}
23+
}
24+
ENDJSON;
25+
26+
$bson = MongoDB\BSON\fromJSON($a);
27+
var_dump(MongoDB\BSON\toPHP($bson));
28+
?>
29+
===DONE===
30+
<?php exit(0); ?>
31+
--EXPECTF--
32+
object(stdClass)#%d (%d) {
33+
["value"]=>
34+
object(stdClass)#%d (%d) {
35+
["payload"]=>
36+
object(stdClass)#%d (%d) {
37+
["PayloadMasterDataMeteringPointPartyEvent"]=>
38+
object(stdClass)#%d (%d) {
39+
["MeteringPointPartyDetailMeteringPointPartyCharacteristic"]=>
40+
object(stdClass)#%d (%d) {
41+
["AdministrativePartyMPAdministrativeParty"]=>
42+
array(%d) {
43+
[0]=>
44+
object(stdClass)#%d (%d) {
45+
["AdministrativePartyAddressLocationAddress"]=>
46+
object(stdClass)#%d (%d) {
47+
["StreetCode"]=>
48+
object(stdClass)#%d (%d) {
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
===DONE===

0 commit comments

Comments
 (0)