Skip to content

Commit 0920390

Browse files
Bugfix: routing_key or exchange with length 255 no launger causes an ArithmeticOverflow (#1094)
fixes a bug where using routing_key or exchange with length 255 causes an ArithmeticOverflow. Fixes #1093
1 parent 6d56229 commit 0920390

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

spec/storage_spec.cr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,31 @@ describe LavinMQ::AMQP::DurableQueue do
164164
end
165165
end
166166
end
167+
168+
# ArithmeticOverflow error when routing key length = 255
169+
# https://github.com/cloudamqp/lavinmq/issues/1093
170+
it "should handle routing key length = 255" do
171+
rk = "a" * 255
172+
with_amqp_server do |s|
173+
vhost = s.vhosts.create("test_vhost")
174+
with_channel(s, vhost: vhost.name) do |ch|
175+
q = ch.queue(rk, durable: true)
176+
queue = vhost.queues[rk].as(LavinMQ::AMQP::DurableQueue)
177+
q.publish_confirm "a"
178+
store = LavinMQ::Queue::MessageStore.new(queue.@msg_store.@queue_data_dir, nil)
179+
180+
if env = store.shift?
181+
if msg = env.message
182+
msg.routing_key.should eq rk
183+
else
184+
fail "no message"
185+
end
186+
else
187+
fail "no message"
188+
end
189+
end
190+
end
191+
end
167192
end
168193

169194
describe LavinMQ::VHost do

src/lavinmq/message.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ module LavinMQ
3838
def self.skip(io, format = IO::ByteFormat::SystemEndian) : UInt64
3939
skipped = 0_u64
4040
skipped += io.skip(sizeof(UInt64)) # ts
41-
skipped += io.skip(io.read_byte || raise IO::EOFError.new) + 1 # ex
42-
skipped += io.skip(io.read_byte || raise IO::EOFError.new) + 1 # rk
41+
skipped += 1 + io.skip(io.read_byte || raise IO::EOFError.new) # ex
42+
skipped += 1 + io.skip(io.read_byte || raise IO::EOFError.new) # rk
4343
skipped += AMQ::Protocol::Properties.skip(io, format)
4444
skipped += io.skip(UInt64.from_io io, format) + sizeof(UInt64)
4545
skipped

0 commit comments

Comments
 (0)