浏览代码

Fix the issue for parsing zero length message (#6592)

* When length is zero, substr returns null instead of emptry string, which breaks the invariable for message.
* Tested in https://github.com/protocolbuffers/protobuf/pull/6560
Paul Yang 6 年之前
父节点
当前提交
e9d4e4acbc
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      php/src/Google/Protobuf/Internal/CodedInputStream.php

+ 6 - 2
php/src/Google/Protobuf/Internal/CodedInputStream.php

@@ -299,8 +299,12 @@ class CodedInputStream
             return false;
         }
 
-        $buffer = substr($this->buffer, $this->current, $size);
-        $this->advance($size);
+        if ($size === 0) {
+          $buffer = "";
+        } else {
+          $buffer = substr($this->buffer, $this->current, $size);
+          $this->advance($size);
+        }
 
         return true;
     }