Преглед изворни кода

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;
             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;
         return true;
     }
     }