WebSocket: Could not handle zero length text frame.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Aug 2011 07:06:56 +0000 (07:06 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Aug 2011 07:06:56 +0000 (07:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=65592

Patch by Takashi Toyoshima <toyoshim@chromium.org> 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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@92262 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/websocket/tests/hybi/zero-length-text-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/zero-length-text.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/zero-length-text_wsh.py [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/websockets/WebSocketChannel.cpp

index b5763d2..64a5a42 100644 (file)
@@ -1,3 +1,14 @@
+2011-08-03  Takashi Toyoshima  <toyoshim@chromium.org>
+
+        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  <toyoshim@chromium.org>
 
         WebSocket: Should be closed by receiving invalid continuation frame.
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text-expected.txt b/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text-expected.txt
new file mode 100644 (file)
index 0000000..8547ef8
--- /dev/null
@@ -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
+
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text.html b/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text.html
new file mode 100644 (file)
index 0000000..38feb4a
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<link rel="stylesheet" href="../../../../js-test-resources/js-test-style.css">
+<script src="../../../../js-test-resources/js-test-pre.js"></script>
+</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="../../../../js-test-resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text_wsh.py b/LayoutTests/http/tests/websocket/tests/hybi/zero-length-text_wsh.py
new file mode 100644 (file)
index 0000000..19954e2
--- /dev/null
@@ -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)
index cb3d55d..976553c 100644 (file)
@@ -1,3 +1,15 @@
+2011-08-03  Takashi Toyoshima  <toyoshim@chromium.org>
+
+        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  <psolanki@apple.com>
 
         Crash in ResourceResponse::platformCompare() with USE(CFNETWORK)
index a78b45c..0173e29 100644 (file)
@@ -561,7 +561,11 @@ bool WebSocketChannel::processFrame()
             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 @@ bool WebSocketChannel::processFrame()
 
     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.");