From 822ec43ab58ec06f045485a5f029ef55370c05b1 Mon Sep 17 00:00:00 2001 From: Jonas Termansen Date: Thu, 3 Jan 2019 12:52:46 +0000 Subject: [PATCH] [dart:io] Fix WebSocket deflate compression of empty fragments. It currently compresses the empty fragment to zero bytes. However, RFC 7692 "Compression Extensions for WebSocket" 6.2.3.6. "Generating an Empty Fragment" says that if the compression library produces no data, then an empty uncompressed deflate block is used for this purpose. The 0x00 block has the BFINAL header bit set to 0 and the BTYPE header set to 00 along with 5 bits of padding. This block decodes to zero bytes. Chrome aborts the "Invalid frame header" when it receives a compressed websocket frame with a zero length payload. This change fixes the websocket implementation so it sends the 0x00 byte instead which decodes to the empty data. Bug: https://github.com/dart-lang/sdk/issues/35540 Change-Id: I581bf2cd362a25c5d88c9d9e31e8499a99f5fd13 Reviewed-on: https://dart-review.googlesource.com/c/88187 Reviewed-by: William Hesse Commit-Queue: Jonas Termansen --- sdk/lib/_http/websocket_impl.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sdk/lib/_http/websocket_impl.dart b/sdk/lib/_http/websocket_impl.dart index e27ab20e868..331a0649bea 100644 --- a/sdk/lib/_http/websocket_impl.dart +++ b/sdk/lib/_http/websocket_impl.dart @@ -649,6 +649,15 @@ class _WebSocketPerMessageDeflate { result = result.sublist(0, result.length - 4); } + // RFC 7692 7.2.3.6. "Generating an Empty Fragment" says that if the + // compression library doesn't generate any data when the bufer is empty, + // then an empty uncompressed deflate block is used for this purpose. The + // 0x00 block has the BFINAL header bit set to 0 and the BTYPE header set to + // 00 along with 5 bits of padding. This block decodes to zero bytes. + if (result.length == 0) { + return [0x00]; + } + return result; } }