Title: [92262] trunk
Revision
92262
Author
[email protected]
Date
2011-08-03 00:06:56 -0700 (Wed, 03 Aug 2011)

Log Message

WebSocket: Could not handle zero length text frame.
https://bugs.webkit.org/show_bug.cgi?id=65592

Patch by Takashi Toyoshima <[email protected]> on 2011-08-03
Reviewed by Kent Tamura.

Source/WebCore:

Test: http/tests/websocket/tests/hybi/zero-length-text.html

* websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::processFrame):

LayoutTests:

* http/tests/websocket/tests/hybi/zero-length-text-expected.txt: Added.
* http/tests/websocket/tests/hybi/zero-length-text.html: Added.
* http/tests/websocket/tests/hybi/zero-length-text_wsh.py: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (92261 => 92262)


--- trunk/LayoutTests/ChangeLog	2011-08-03 05:07:51 UTC (rev 92261)
+++ trunk/LayoutTests/ChangeLog	2011-08-03 07:06:56 UTC (rev 92262)
@@ -1,3 +1,14 @@
+2011-08-03  Takashi Toyoshima  <[email protected]>
+
+        WebSocket: Could not handle zero length text frame.
+        https://bugs.webkit.org/show_bug.cgi?id=65592
+
+        Reviewed by Kent Tamura.
+
+        * http/tests/websocket/tests/hybi/zero-length-text-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/zero-length-text.html: Added.
+        * http/tests/websocket/tests/hybi/zero-length-text_wsh.py: Added.
+
 2011-08-02  Takashi Toyoshima  <[email protected]>
 
         WebSocket: Should be closed by receiving invalid continuation frame.

Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text-expected.txt (0 => 92262)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text-expected.txt	2011-08-03 07:06:56 UTC (rev 92262)
@@ -0,0 +1,17 @@
+Test whether WebSocket handles zero length text frame correctly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+onopen() was called.
+onmessage() was called. (message = "")
+onmessage() was called. (message = "This first text should be received.")
+onmessage() was called. (message = "")
+onmessage() was called. (message = "This second text should be received, too.")
+onclose() was called.
+PASS closeEvent.wasClean is true
+PASS sequence is 4
+PASS receivedText is expectedText
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text.html (0 => 92262)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text.html	2011-08-03 07:06:56 UTC (rev 92262)
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description("Test whether WebSocket handles zero length text frame correctly.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+var ws = new WebSocket("ws://127.0.0.1:8880/websocket/tests/hybi/zero-length-text");
+var closeEvent;
+var sequence = 0;
+var receivedText = "";
+var expectedText = "This first text should be received.This second text should be received, too.";
+
+ws._onopen_ = function()
+{
+    debug("onopen() was called.");
+};
+
+ws._onmessage_ = function(event)
+{
+    var message = event.data;
+    sequence++;
+    if (sequence > 4) {
+        testFailed("onmessage() was called. (message = \"" + message + "\")");
+    } else {
+        debug("onmessage() was called. (message = \"" + message + "\")");
+        receivedText += message;
+    }
+};
+
+ws._onclose_ = function(event)
+{
+    debug("onclose() was called.");
+    closeEvent = event;
+    shouldBeTrue("closeEvent.wasClean");
+    shouldBe("sequence", "4");
+    shouldBe("receivedText", "expectedText");
+    finishJSTest();
+};
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text_wsh.py (0 => 92262)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text_wsh.py	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text_wsh.py	2011-08-03 07:06:56 UTC (rev 92262)
@@ -0,0 +1,41 @@
+from mod_pywebsocket import common
+from mod_pywebsocket import stream
+
+
+def web_socket_do_extra_handshake(request):
+    pass
+
+
+def web_socket_transfer_data(request):
+    payload1 = 'This first text should be received.'
+    payload2 = 'This second text '
+    payload3 = 'should be received, too.'
+
+    # send ''
+    request.connection.write(stream.create_header(common.OPCODE_TEXT,
+                                                  0,
+                                                  1, 0, 0, 0, 0))
+
+    # send payload1
+    request.connection.write(stream.create_header(common.OPCODE_TEXT,
+                                                  len(payload1),
+                                                  1, 0, 0, 0, 0) + payload1)
+
+    # send '' + ''
+    request.connection.write(stream.create_header(common.OPCODE_TEXT,
+                                                  0,
+                                                  0, 0, 0, 0, 0))
+    request.connection.write(stream.create_header(common.OPCODE_CONTINUATION,
+                                                  0,
+                                                  1, 0, 0, 0, 0))
+
+    # send payload2 + '' + payload3
+    request.connection.write(stream.create_header(common.OPCODE_TEXT,
+                                                  len(payload2),
+                                                  0, 0, 0, 0, 0) + payload2)
+    request.connection.write(stream.create_header(common.OPCODE_CONTINUATION,
+                                                  0,
+                                                  0, 0, 0, 0, 0))
+    request.connection.write(stream.create_header(common.OPCODE_CONTINUATION,
+                                                  len(payload3),
+                                                  1, 0, 0, 0, 0) + payload3)

Modified: trunk/Source/WebCore/ChangeLog (92261 => 92262)


--- trunk/Source/WebCore/ChangeLog	2011-08-03 05:07:51 UTC (rev 92261)
+++ trunk/Source/WebCore/ChangeLog	2011-08-03 07:06:56 UTC (rev 92262)
@@ -1,3 +1,15 @@
+2011-08-03  Takashi Toyoshima  <[email protected]>
+
+        WebSocket: Could not handle zero length text frame.
+        https://bugs.webkit.org/show_bug.cgi?id=65592
+
+        Reviewed by Kent Tamura.
+
+        Test: http/tests/websocket/tests/hybi/zero-length-text.html
+
+        * websockets/WebSocketChannel.cpp:
+        (WebCore::WebSocketChannel::processFrame):
+
 2011-08-02  Pratik Solanki  <[email protected]>
 
         Crash in ResourceResponse::platformCompare() with USE(CFNETWORK)

Modified: trunk/Source/WebCore/websockets/WebSocketChannel.cpp (92261 => 92262)


--- trunk/Source/WebCore/websockets/WebSocketChannel.cpp	2011-08-03 05:07:51 UTC (rev 92261)
+++ trunk/Source/WebCore/websockets/WebSocketChannel.cpp	2011-08-03 07:06:56 UTC (rev 92262)
@@ -561,7 +561,11 @@
             m_continuousFrameData.swap(continuousFrameData);
             m_hasContinuousFrame = false;
             if (m_continuousFrameOpCode == OpCodeText) {
-                String message = String::fromUTF8(continuousFrameData.data(), continuousFrameData.size());
+                String message;
+                if (continuousFrameData.size())
+                    message = String::fromUTF8(continuousFrameData.data(), continuousFrameData.size());
+                else
+                    message = "";
                 if (message.isNull())
                     fail("Could not decode a text frame as UTF-8.");
                 else
@@ -575,7 +579,11 @@
 
     case OpCodeText:
         if (frame.final) {
-            String message = String::fromUTF8(frame.payload, frame.payloadLength);
+            String message;
+            if (frame.payloadLength)
+                message = String::fromUTF8(frame.payload, frame.payloadLength);
+            else
+                message = "";
             skipBuffer(frame.frameEnd - m_buffer);
             if (message.isNull())
                 fail("Could not decode a text frame as UTF-8.");
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to