Skip to content

Commit 6e880e4

Browse files
committed
Allow 256MiB payloads
1 parent 1e15e68 commit 6e880e4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/mqtt/protocol/io.cr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
require "./packets"
22

33
module MQTT
4-
MAX_REMAINING_LENGTH = (128 * 128 * 128).to_u32
4+
MAX_PAYLOAD_SIZE = 268_435_455u32 # 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 & 127u32) * 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

0 commit comments

Comments
 (0)