Skip to content

Commit

Permalink
Do not use multibyte capable functions to calculate length of headers
Browse files Browse the repository at this point in the history
Sometimes mb_strlen() will recognize a certain sequence of bits as a
multibyte character and act according to what is was designed to do:
avoid this behaviour by using a function that does not have support for
multibyte.
  • Loading branch information
unreal4u committed Jan 8, 2018
1 parent f08482b commit 560037b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function sendSocketData(WritableContentInterface $object): string
$writableString = $object->createSendableMessage();
$sizeOfString = \strlen($writableString);
$writtenBytes = fwrite($this->socket, $writableString, $sizeOfString);
// $this->logger->debug('Sent string', ['binaryString' => str2bin($writableString)]); // Handy for debugging
if ($writtenBytes !== $sizeOfString) {
$this->logger->error('Written bytes do NOT correspond with size of string!', [
'writtenBytes' => $writtenBytes,
Expand Down
2 changes: 1 addition & 1 deletion src/Internals/WritableContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ final public function createSendableMessage(): string
$this->logger->debug('Creating variable header', ['variableHeader' => base64_encode($variableHeader)]);
$payload = $this->createPayload();
$this->logger->debug('Creating payload', ['payload' => base64_encode($payload)]);
$fixedHeader = $this->createFixedHeader(mb_strlen($variableHeader . $payload));
$fixedHeader = $this->createFixedHeader(\strlen($variableHeader . $payload));
$this->logger->debug('Created fixed header', ['fixedHeader' => base64_encode($fixedHeader)]);

return $fixedHeader . $variableHeader . $payload;
Expand Down
1 change: 1 addition & 0 deletions src/Protocol/Subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function setPacketIdentifier(int $packetIdentifier): Subscribe
}

$this->packetIdentifier = $packetIdentifier;
$this->logger->debug('Setting packet identifier', ['current' => $this->packetIdentifier]);

return $this;
}
Expand Down

0 comments on commit 560037b

Please sign in to comment.