GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(websocket): handle empty frames in attach streams · docker-php/docker-php@17b620c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/Stream
    • AttachWebsocketStream.php
  • tests/Stream
    • AttachWebsocketStreamTest.php
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Stream/AttachWebsocketStream.php‎

Copy file name to clipboardExpand all lines: src/Stream/AttachWebsocketStream.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public function read($waitTime = 0, $waitMicroTime = 200000, $getFrame = false)
156156
private function socketRead($length)
157157
{
158158
$read = '';
159+
// Empty frames carry no payload; fread() rejects a zero length.
160+
if ($length <= 0) {
161+
return $read;
162+
}
159163

160164
do {
161165
$read .= fread($this->socket, $length - \strlen($read));
Collapse file

‎tests/Stream/AttachWebsocketStreamTest.php‎

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Docker\Tests\Stream;
6+
7+
use Docker\Stream\AttachWebsocketStream;
8+
use Nyholm\Psr7\Stream;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class AttachWebsocketStreamTest extends TestCase
12+
{
13+
public function testReadsEmptyFrameBeforePayload(): void
14+
{
15+
[$client, $server] = stream_socket_pair(\STREAM_PF_UNIX, \STREAM_SOCK_STREAM, \STREAM_IPPROTO_IP);
16+
// An empty text frame followed by an unmasked "hi" text frame.
17+
fwrite($server, "\x81\x00\x81\x02hi");
18+
19+
$stream = new AttachWebsocketStream(Stream::create($client));
20+
21+
$this->assertSame('', $stream->read());
22+
$this->assertSame('hi', $stream->read());
23+
fclose($server);
24+
}
25+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.