Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/websocket/driver/hybi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ def parse_extended_length(buffer)
@frame.length = buffer.unpack(PACK_FORMATS[buffer.bytesize]).first
@stage = @frame.masked ? 3 : 4

if (buffer.bytesize == 2 && @frame.length < 126) ||
(buffer.bytesize == 8 && @frame.length < 65_536)
return fail(:protocol_error, 'Received frame with non-minimal length encoding')
end

if buffer.bytesize == 8 && (buffer.getbyte(0) & MASK) == MASK
return fail(:protocol_error, 'Received frame with invalid 64-bit length')
end

unless MESSAGE_OPCODES.include?(@frame.opcode) or @frame.length <= 125
return fail(:protocol_error, "Received control frame having too long payload: #{ @frame.length }")
end
Expand Down