From 82213fd3a529121b76746f2572ea41be8244d2cf Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Tue, 3 Sep 2019 09:13:38 -0700 Subject: [PATCH] Message type (TEXT or BINARY) is invalid for received fragmented messages (fix autobahn test: 5.3 through 5.8 Fragmentation) --- DOCKER_VERSION | 2 +- docs/CHANGELOG.md | 8 ++++++-- ixwebsocket/IXWebSocketTransport.cpp | 16 ++++++++++------ ixwebsocket/IXWebSocketTransport.h | 5 +++++ ixwebsocket/IXWebSocketVersion.h | 2 +- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/DOCKER_VERSION b/DOCKER_VERSION index 61fcc873..cdb98d26 100644 --- a/DOCKER_VERSION +++ b/DOCKER_VERSION @@ -1 +1 @@ -5.1.2 +5.1.3 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index cede63f8..c6ed6234 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,13 +1,17 @@ # Changelog All notable changes to this project will be documented in this file. +## [5.1.3] - 2019-09-03 + +Message type (TEXT or BINARY) is invalid for received fragmented messages (fix autobahn test: 5.3 through 5.8 Fragmentation) + ## [5.1.2] - 2019-09-02 -Ping and Pong messages cannot be fragmented (autobahn test: 5.1 and 5.2 Fragmentation) +Ping and Pong messages cannot be fragmented (fix autobahn test: 5.1 and 5.2 Fragmentation) ## [5.1.1] - 2019-09-01 -Close connections when reserved bits are used (autobahn test: 3 Reserved Bits) +Close connections when reserved bits are used (fix autobahn test: 3.X Reserved Bits) ## [5.1.0] - 2019-08-31 diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp index 8280a401..9c0d7d3f 100644 --- a/ixwebsocket/IXWebSocketTransport.cpp +++ b/ixwebsocket/IXWebSocketTransport.cpp @@ -565,17 +565,20 @@ namespace ix ) { unmaskReceiveBuffer(ws); - MessageKind messageKind = - (ws.opcode == wsheader_type::TEXT_FRAME) - ? MessageKind::MSG_TEXT - : MessageKind::MSG_BINARY; + if (ws.opcode != wsheader_type::CONTINUATION) + { + _fragmentedMessageKind = + (ws.opcode == wsheader_type::TEXT_FRAME) + ? MessageKind::MSG_TEXT + : MessageKind::MSG_BINARY; + } // // Usual case. Small unfragmented messages // if (ws.fin && _chunks.empty()) { - emitMessage(messageKind, + emitMessage(_fragmentedMessageKind, std::string(_rxbuf.begin()+ws.header_size, _rxbuf.begin()+ws.header_size+(size_t) ws.N), ws, @@ -595,7 +598,8 @@ namespace ix _rxbuf.begin()+ws.header_size+(size_t)ws.N)); if (ws.fin) { - emitMessage(messageKind, getMergedChunks(), ws, onMessageCallback); + emitMessage(_fragmentedMessageKind, getMergedChunks(), + ws, onMessageCallback); _chunks.clear(); } else diff --git a/ixwebsocket/IXWebSocketTransport.h b/ixwebsocket/IXWebSocketTransport.h index 32a864c9..331d5fdf 100644 --- a/ixwebsocket/IXWebSocketTransport.h +++ b/ixwebsocket/IXWebSocketTransport.h @@ -151,6 +151,11 @@ namespace ix // size increased 2 fold, while appending to a list has a fixed cost. std::list> _chunks; + // Record the message kind (will be TEXT or BINARY) for a fragmented + // message, present in the first chunk, since the final chunk will be a + // CONTINUATION opcode and doesn't tell the full message kind + MessageKind _fragmentedMessageKind; + // Fragments are 32K long static constexpr size_t kChunkSize = 1 << 15; diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 5009574c..a6195514 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "5.1.2" +#define IX_WEBSOCKET_VERSION "5.1.3"