Skip to content

Commit c8e9b27

Browse files
protobuf-github-botshaod2
authored andcommitted
php: Fix that recursion limit is not enforced.
#25067 PiperOrigin-RevId: 856286406
1 parent a594f97 commit c8e9b27

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

php/src/Google/Protobuf/Internal/CodedInputStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public function incrementRecursionDepthAndPushLimit(
337337
$byte_limit, &$old_limit, &$recursion_budget)
338338
{
339339
$old_limit = $this->pushLimit($byte_limit);
340-
$recursion_limit = --$this->recursion_limit;
340+
$recursion_budget = --$this->recursion_budget;
341341
}
342342

343343
public function decrementRecursionDepthAndPopLimit($byte_limit)

php/tests/EncodeDecodeTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,31 @@ public function testDecodeNegativeInt32()
603603
$this->assertEquals(-1, $m->getOptionalInt32());
604604
}
605605

606+
private function makeRecursiveMessage($depth) {
607+
$m = new TestMessage();
608+
$m->setOptionalInt32(1);
609+
if ($depth == 0) {
610+
return $m;
611+
}
612+
$m->setRecursive($this->makeRecursiveMessage($depth - 1));
613+
return $m;
614+
}
615+
616+
public function testRecursiveMessage() {
617+
$payload = $this->makeRecursiveMessage(99)->serializeToString();
618+
619+
$m = new TestMessage();
620+
$m->mergeFromString($payload);
621+
}
622+
623+
public function testOverlyRecursiveMessage() {
624+
$this->expectException(Exception::class);
625+
$payload = $this->makeRecursiveMessage(101)->serializeToString();
626+
627+
$m = new TestMessage();
628+
$m->mergeFromString($payload);
629+
}
630+
606631
public function testRandomFieldOrder()
607632
{
608633
$m = new TestRandomFieldOrder();

0 commit comments

Comments
 (0)