Skip to content

Commit d8588c3

Browse files
Pure PHP: cleanly ignore bits in the 10-byte varints with bit above LSB set.
Still error out if the MSB in that is set (implying it would be an 11+ byte varint). This is not really functional change; today this flow is just silently 'weird' where readVarint64() can return a float64 since php silently promotes the type when it doesn't fit. PiperOrigin-RevId: 899065019
1 parent b7e554a commit d8588c3

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

php/tests/PhpImplementationTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,16 @@ public function testReadVarint64()
379379
$input = new CodedInputStream(hex2bin(''));
380380
$this->assertFalse($input->readVarint64($var));
381381

382-
// The largest varint is 10 bytes long.
382+
// varints which are >10 bytes long aren't allowed
383383
$input = new CodedInputStream(hex2bin('8080808080808080808001'));
384384
$this->assertFalse($input->readVarint64($var));
385385

386+
// 10-byte varint with high bits set in the 10th byte.
387+
// Bits above bit 0 in the 10th byte are discarded.
388+
$input = new CodedInputStream(hex2bin('87808080808080808002'));
389+
$this->assertTrue($input->readVarint64($var));
390+
$this->assertSame(7, $var);
391+
386392
// Corrupted varint.
387393
$input = new CodedInputStream(hex2bin('808080'));
388394
$this->assertFalse($input->readVarint64($var));

0 commit comments

Comments
 (0)