Skip to content

Commit 60e93d2

Browse files
protobuf-github-botshaod2
authored andcommitted
Check that readRaw does not accept negative length value.
Fixes #24159 PiperOrigin-RevId: 855837030
1 parent c8e9b27 commit 60e93d2

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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

php/tests/EncodeDecodeTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,13 @@ 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+
606613
private function makeRecursiveMessage($depth) {
607614
$m = new TestMessage();
608615
$m->setOptionalInt32(1);

0 commit comments

Comments
 (0)