Merge pull request #65 from Domochip/master
Handle up to 2GB payload on PHP32bits
This commit is contained in:
commit
382a3ed941
@ -158,9 +158,19 @@ class MessageBuffer {
|
|||||||
$payloadLenBytes = $payload_length === 126 ? 2 : 8;
|
$payloadLenBytes = $payload_length === 126 ? 2 : 8;
|
||||||
$headerSize += $payloadLenBytes;
|
$headerSize += $payloadLenBytes;
|
||||||
$bytesToUpack = substr($data, $frameStart + 2, $payloadLenBytes);
|
$bytesToUpack = substr($data, $frameStart + 2, $payloadLenBytes);
|
||||||
$payload_length = $payload_length === 126
|
$payloadLenOver2GB = false;
|
||||||
? unpack('n', $bytesToUpack)[1]
|
|
||||||
: unpack('J', $bytesToUpack)[1];
|
if ($payload_length === 126){
|
||||||
|
$payload_length = unpack('n', $bytesToUpack)[1];
|
||||||
|
} else {
|
||||||
|
$payloadLenOver2GB = unpack('N', $bytesToUpack)[1] > 0; //Decode only the 4 first bytes
|
||||||
|
if (PHP_INT_SIZE == 4) { // if 32bits PHP
|
||||||
|
$bytesToUpack = substr($bytesToUpack, 4); //Keep only 4 last bytes
|
||||||
|
$payload_length = unpack('N', $bytesToUpack)[1];
|
||||||
|
} else {
|
||||||
|
$payload_length = unpack('J', $bytesToUpack)[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$closeFrame = null;
|
$closeFrame = null;
|
||||||
@ -170,6 +180,10 @@ class MessageBuffer {
|
|||||||
$closeFrame = $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Invalid frame length');
|
$closeFrame = $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Invalid frame length');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$closeFrame && PHP_INT_SIZE == 4 && $payloadLenOver2GB) {
|
||||||
|
$closeFrame = $this->newCloseFrame(Frame::CLOSE_TOO_BIG, 'Frame over 2GB can\'t be handled on 32bits PHP');
|
||||||
|
}
|
||||||
|
|
||||||
if (!$closeFrame && $this->maxFramePayloadSize > 1 && $payload_length > $this->maxFramePayloadSize) {
|
if (!$closeFrame && $this->maxFramePayloadSize > 1 && $payload_length > $this->maxFramePayloadSize) {
|
||||||
$closeFrame = $this->newCloseFrame(Frame::CLOSE_TOO_BIG, 'Maximum frame size exceeded');
|
$closeFrame = $this->newCloseFrame(Frame::CLOSE_TOO_BIG, 'Maximum frame size exceeded');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user