Title: [131395] trunk
Revision
131395
Author
ba...@chromium.org
Date
2012-10-15 18:40:45 -0700 (Mon, 15 Oct 2012)

Log Message

[WebSocket] WebSocketInflater should handle BFINAL = 1 blocks
https://bugs.webkit.org/show_bug.cgi?id=99282

Reviewed by Yuta Kitamura.

Source/WebCore:

Reset decompression state if WebSocketInflater decompress a block with
BFINAL set to 1.

Test: http/tests/websocket/tests/hybi/deflate-frame-set-bfinal.html

* Modules/websockets/WebSocketDeflater.cpp:
(WebCore::WebSocketInflater::addBytes):
Reset decompression state if inflate() returns Z_STREAM_END, which means the BFINAL
of the current block was set to 1.
(WebCore::WebSocketInflater::finish): Add an assertion.

LayoutTests:

Added a test for receiving compressed blocks with BFINAL set to 1.

* http/tests/websocket/tests/hybi/deflate-frame-set-bfinal-expected.txt: Added.
* http/tests/websocket/tests/hybi/deflate-frame-set-bfinal.html: Added.
* http/tests/websocket/tests/hybi/deflate-frame_wsh.py:
(web_socket_do_extra_handshake): Call set_bfinal() if the 'set_bfinal' parameter is passed.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (131394 => 131395)


--- trunk/LayoutTests/ChangeLog	2012-10-16 01:20:18 UTC (rev 131394)
+++ trunk/LayoutTests/ChangeLog	2012-10-16 01:40:45 UTC (rev 131395)
@@ -1,3 +1,17 @@
+2012-10-15  Kenichi Ishibashi  <ba...@chromium.org>
+
+        [WebSocket] WebSocketInflater should handle BFINAL = 1 blocks
+        https://bugs.webkit.org/show_bug.cgi?id=99282
+
+        Reviewed by Yuta Kitamura.
+
+        Added a test for receiving compressed blocks with BFINAL set to 1.
+
+        * http/tests/websocket/tests/hybi/deflate-frame-set-bfinal-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/deflate-frame-set-bfinal.html: Added.
+        * http/tests/websocket/tests/hybi/deflate-frame_wsh.py:
+        (web_socket_do_extra_handshake): Call set_bfinal() if the 'set_bfinal' parameter is passed.
+
 2012-10-15  Simon Fraser  <simon.fra...@apple.com>
 
         Fix GraphicsLayer visible rect computation when scrolling in WebKit1

Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/deflate-frame-set-bfinal-expected.txt (0 => 131395)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/deflate-frame-set-bfinal-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/deflate-frame-set-bfinal-expected.txt	2012-10-16 01:40:45 UTC (rev 131395)
@@ -0,0 +1,16 @@
+Test receiving compressed frames with BFINAL = 1.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Sending message: "Hello"
+PASS event.data is 'Hello'
+Sending message: "World"
+PASS event.data is 'World'
+Sending message: "Goodbye"
+PASS event.data is 'Goodbye'
+onclose() was called.
+PASS closeEvent.wasClean is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/deflate-frame-set-bfinal.html (0 => 131395)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/deflate-frame-set-bfinal.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/deflate-frame-set-bfinal.html	2012-10-16 01:40:45 UTC (rev 131395)
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description("Test receiving compressed frames with BFINAL = 1.");
+
+window.jsTestIsAsync = true;
+
+var closeEvent;
+var ws;
+var messageIndex;
+
+var messages = [
+    "Hello",
+    "World",
+    "Goodbye"
+];
+
+ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/deflate-frame?set_bfinal");
+
+ws._onopen_ = function(event)
+{
+    messageIndex = 0;
+    debug("Sending message: \"" + messages[messageIndex] + "\"");
+    ws.send(messages[messageIndex]);
+};
+
+ws._onmessage_ = function(event)
+{
+    shouldBe("event.data", "'" + messages[messageIndex] + "'");
+    if (messageIndex === messages.length - 1)
+        ws.close();
+    else {
+        messageIndex += 1;
+        debug("Sending message: \"" + messages[messageIndex] + "\"");
+        ws.send(messages[messageIndex]);
+    }
+};
+
+ws._onclose_ = function(event)
+{
+    debug("onclose() was called.");
+    closeEvent = event;
+    shouldBeTrue("closeEvent.wasClean");
+    finishJSTest();
+};
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/deflate-frame_wsh.py (131394 => 131395)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/deflate-frame_wsh.py	2012-10-16 01:20:18 UTC (rev 131394)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/deflate-frame_wsh.py	2012-10-16 01:40:45 UTC (rev 131395)
@@ -58,6 +58,8 @@
         processor.set_response_window_bits(window_bits)
     if 'no_context_takeover' in parameters:
         processor.set_response_no_context_takeover(True)
+    if 'set_bfinal' in parameters:
+        processor.set_bfinal(True)
 
 
 def web_socket_transfer_data(request):

Modified: trunk/Source/WebCore/ChangeLog (131394 => 131395)


--- trunk/Source/WebCore/ChangeLog	2012-10-16 01:20:18 UTC (rev 131394)
+++ trunk/Source/WebCore/ChangeLog	2012-10-16 01:40:45 UTC (rev 131395)
@@ -1,3 +1,21 @@
+2012-10-15  Kenichi Ishibashi  <ba...@chromium.org>
+
+        [WebSocket] WebSocketInflater should handle BFINAL = 1 blocks
+        https://bugs.webkit.org/show_bug.cgi?id=99282
+
+        Reviewed by Yuta Kitamura.
+
+        Reset decompression state if WebSocketInflater decompress a block with
+        BFINAL set to 1.
+
+        Test: http/tests/websocket/tests/hybi/deflate-frame-set-bfinal.html
+
+        * Modules/websockets/WebSocketDeflater.cpp:
+        (WebCore::WebSocketInflater::addBytes):
+        Reset decompression state if inflate() returns Z_STREAM_END, which means the BFINAL
+        of the current block was set to 1.
+        (WebCore::WebSocketInflater::finish): Add an assertion.
+
 2012-10-15  Simon Fraser  <simon.fra...@apple.com>
 
         Fix GraphicsLayer visible rect computation when scrolling in WebKit1

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketDeflater.cpp (131394 => 131395)


--- trunk/Source/WebCore/Modules/websockets/WebSocketDeflater.cpp	2012-10-16 01:20:18 UTC (rev 131394)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketDeflater.cpp	2012-10-16 01:40:45 UTC (rev 131395)
@@ -168,8 +168,15 @@
         m_buffer.shrink(writePosition + availableCapacity - m_stream->avail_out);
         if (result == Z_BUF_ERROR)
             continue;
+        if (result == Z_STREAM_END) {
+            // Received a block with BFINAL set to 1. Reset decompression state.
+            if (inflateReset(m_stream.get()) != Z_OK)
+                return false;
+            continue;
+        }
         if (result != Z_OK)
             return false;
+        ASSERT(remainingLength > m_stream->avail_in);
     }
     ASSERT(consumedSoFar == length);
     return true;
@@ -195,6 +202,7 @@
             continue;
         if (result != Z_OK && result != Z_STREAM_END)
             return false;
+        ASSERT(remainingLength > m_stream->avail_in);
     }
     ASSERT(consumedSoFar == strippedLength);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to