File tree Expand file tree Collapse file tree 2 files changed +6
-7
lines changed
Expand file tree Collapse file tree 2 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -304,20 +304,18 @@ describe MQTT::Protocol::IO do
304304 end
305305 end
306306
307- it " can checks max_packet_size on remainin length" do
307+ it " checks max_packet_size on remaining length" do
308308 mio = IO ::Memory .new
309309 mio.write Bytes [0xFF u8, 0xFF u8, 0xFF u8, 0x7F u8]
310310
311311 mio.rewind
312312
313313 io = MQTT ::Protocol ::IO .new(mio)
314314
315+ io = MQTT ::Protocol ::IO .new(mio, max_packet_size: 268435454 u32 )
315316 expect_raises(MQTT ::Protocol ::Error ::PacketTooLarge ) do
316317 io.read_remaining_length
317318 end
318- mio.rewind
319- io = MQTT ::Protocol ::IO .new(mio, max_packet_size: 268435455 u32 )
320- io.read_remaining_length
321319 end
322320
323321 it " checks read_string for max_packet_size" do
Original file line number Diff line number Diff line change 11require " ./packets"
22
33module MQTT
4- MAX_REMAINING_LENGTH = (128 * 128 * 128 ).to_u32
4+ MAX_PAYLOAD_SIZE = 268_435_455 u32 # 256MiB
5+ MAX_MULTIPLIER = (128 * 128 * 128 ).to_u32
56
67 module Protocol
78 struct IO
89 getter io
910
1011 def self.new (io : ::IO , max_packet_size : UInt32 ? = nil ,
1112 byte_format = ::IO ::ByteFormat ::NetworkEndian )
12- new(io, max_packet_size || MAX_REMAINING_LENGTH , byte_format)
13+ new(io, max_packet_size || MAX_PAYLOAD_SIZE , byte_format)
1314 end
1415
1516 protected def initialize (@io : ::IO , @max_packet_size : UInt32 ,
@@ -56,7 +57,7 @@ module MQTT
5657 value += (b.to_u32 & 127 u32 ) * multiplier
5758 break if b & 128 == 0
5859 multiplier *= 128
59- raise Error ::PacketDecode .new " invalid remaining length" if multiplier > MAX_REMAINING_LENGTH
60+ raise Error ::PacketDecode .new " invalid remaining length" if multiplier > MAX_MULTIPLIER
6061 end
6162 raise Error ::PacketTooLarge .new(@max_packet_size , value) if value > @max_packet_size
6263 value
You can’t perform that action at this time.
0 commit comments