File tree Expand file tree Collapse file tree
src/Google/Protobuf/Internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -271,7 +271,8 @@ public function readTag()
271271 public function readRaw ($ size , &$ buffer )
272272 {
273273 $ current_buffer_size = 0 ;
274- if ($ this ->bufferSize () < $ size ) {
274+ // size (varint) read from the wire could be negative.
275+ if ($ size < 0 || $ this ->bufferSize () < $ size ) {
275276 return false ;
276277 }
277278
@@ -337,7 +338,7 @@ public function incrementRecursionDepthAndPushLimit(
337338 $ byte_limit , &$ old_limit , &$ recursion_budget )
338339 {
339340 $ old_limit = $ this ->pushLimit ($ byte_limit );
340- $ recursion_limit = --$ this ->recursion_limit ;
341+ $ recursion_budget = --$ this ->recursion_budget ;
341342 }
342343
343344 public function decrementRecursionDepthAndPopLimit ($ byte_limit )
Original file line number Diff line number Diff line change @@ -603,6 +603,38 @@ public function testDecodeNegativeInt32()
603603 $ this ->assertEquals (-1 , $ m ->getOptionalInt32 ());
604604 }
605605
606+ public function testInvalidVarintLength () {
607+ $ this ->expectException (Exception::class);
608+
609+ $ m = new TestMessage ();
610+ $ m ->mergeFromString (hex2bin ("0afaffffff0f " ));
611+ }
612+
613+ private function makeRecursiveMessage ($ depth ) {
614+ $ m = new TestMessage ();
615+ $ m ->setOptionalInt32 (1 );
616+ if ($ depth == 0 ) {
617+ return $ m ;
618+ }
619+ $ m ->setRecursive ($ this ->makeRecursiveMessage ($ depth - 1 ));
620+ return $ m ;
621+ }
622+
623+ public function testRecursiveMessage () {
624+ $ payload = $ this ->makeRecursiveMessage (99 )->serializeToString ();
625+
626+ $ m = new TestMessage ();
627+ $ m ->mergeFromString ($ payload );
628+ }
629+
630+ public function testOverlyRecursiveMessage () {
631+ $ this ->expectException (Exception::class);
632+ $ payload = $ this ->makeRecursiveMessage (101 )->serializeToString ();
633+
634+ $ m = new TestMessage ();
635+ $ m ->mergeFromString ($ payload );
636+ }
637+
606638 public function testRandomFieldOrder ()
607639 {
608640 $ m = new TestRandomFieldOrder ();
You can’t perform that action at this time.
0 commit comments