From e9d4e4acbc037dc580eec06fb4c2670d0b74a172 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 30 Aug 2019 10:47:25 -0700 Subject: [PATCH] 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 --- php/src/Google/Protobuf/Internal/CodedInputStream.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/php/src/Google/Protobuf/Internal/CodedInputStream.php b/php/src/Google/Protobuf/Internal/CodedInputStream.php index 33f4a456af..33b1f5a9ba 100644 --- a/php/src/Google/Protobuf/Internal/CodedInputStream.php +++ b/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; }