Browse Source

Fixed PHP to support field numbers >=2**28. (#8235)

Joshua Haberman 4 years ago
parent
commit
d5079ed7db

File diff suppressed because it is too large
+ 1554 - 310
php/ext/google/protobuf/php-upb.c


File diff suppressed because it is too large
+ 588 - 55
php/ext/google/protobuf/php-upb.h


+ 2 - 2
php/src/Google/Protobuf/Internal/GPBWire.php

@@ -50,8 +50,8 @@ class GPBWire
 
     public static function getTagFieldNumber($tag)
     {
-        return ($tag >> self::TAG_TYPE_BITS) &
-            (1 << ((PHP_INT_SIZE * 8) - self::TAG_TYPE_BITS)) - 1;
+        // We have to mask because PHP has no arithmetic shift.
+        return ($tag >> self::TAG_TYPE_BITS) & 0x1fffffff;
     }
 
     public static function getTagWireType($tag)

+ 10 - 0
php/tests/EncodeDecodeTest.php

@@ -14,6 +14,7 @@ use Foo\TestStringValue;
 use Foo\TestBytesValue;
 use Foo\TestAny;
 use Foo\TestEnum;
+use Foo\TestLargeFieldNumber;
 use Foo\TestMessage;
 use Foo\TestMessage\Sub;
 use Foo\TestPackedMessage;
@@ -529,6 +530,15 @@ class EncodeDecodeTest extends TestBase
         $this->assertSame("", $data);
     }
 
+    public function testLargeFieldNumber()
+    {
+        $m = new TestLargeFieldNumber(['large_field_number' => 5]);
+        $data = $m->serializeToString();
+        $m2 = new TestLargeFieldNumber();
+        $m2->mergeFromString($data);
+        $this->assertSame(5, $m2->getLargeFieldNumber());
+    }
+
     public function testDecodeInvalidInt32()
     {
         $this->expectException(Exception::class);

+ 4 - 0
php/tests/proto/test.proto

@@ -220,6 +220,10 @@ message TestRandomFieldOrder {
   string tag14 = 160;
 }
 
+message TestLargeFieldNumber {
+  int32 large_field_number = 536870911;
+}
+
 message TestReverseFieldOrder {
   repeated int32 a = 2;
   string b = 1;

Some files were not shown because too many files changed in this diff