lib/em-websocket/framing03.rb in em-websocket-0.3.6 vs lib/em-websocket/framing03.rb in em-websocket-0.3.7

- old
+ new

@@ -1,15 +1,10 @@ # encoding: BINARY module EventMachine module WebSocket module Framing03 - - # Set the max frame lenth to very high value (10MB) until there is a - # limit specified in the spec to protect against malicious attacks - MAXIMUM_FRAME_LENGTH = 10 * 1024 * 1024 - def initialize_framing @data = '' @application_data_buffer = '' # Used for MORE frames end @@ -55,13 +50,12 @@ l else length end - # Addition to the spec to protect against malicious requests - if payload_length > MAXIMUM_FRAME_LENGTH - raise DataError, "Frame length too long (#{payload_length} bytes)" + if payload_length > @connection.max_frame_size + raise WSMessageTooBigError, "Frame length too long (#{payload_length} bytes)" end # Check buffer size if @data.getbyte(pointer+payload_length-1) == nil debug [:buffer_incomplete, @data] @@ -76,11 +70,11 @@ application_data = @data.slice!(0...payload_length) frame_type = opcode_to_type(opcode) if frame_type == :continuation && !@frame_type - raise WebSocketError, 'Continuation frame not expected' + raise WSProtocolError, 'Continuation frame not expected' end if more debug [:moreframe, frame_type, application_data] @application_data_buffer << application_data @@ -154,10 +148,10 @@ def type_to_opcode(frame_type) FRAME_TYPES[frame_type] || raise("Unknown frame type") end def opcode_to_type(opcode) - FRAME_TYPES_INVERSE[opcode] || raise(DataError, "Unknown opcode") + FRAME_TYPES_INVERSE[opcode] || raise(WSProtocolError, "Unknown opcode") end def data_frame?(type) DATA_FRAMES.include?(type) end