Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit 84b7d8d

Browse files
committed
Handle empty binary payload when delivering message
Fixes #299
1 parent 6e08b2c commit 84b7d8d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/rabbit_binary_generator.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ build_content_frames(FragsRev, FrameMax, ChannelInt) ->
8383
build_content_frames(SizeAcc, FramesAcc, _FragSizeRem, [],
8484
[], _BodyPayloadMax, _ChannelInt) ->
8585
{SizeAcc, lists:reverse(FramesAcc)};
86+
build_content_frames(SizeAcc, FramesAcc, _FragSizeRem, [],
87+
[<<>>], _BodyPayloadMax, _ChannelInt) ->
88+
{SizeAcc, lists:reverse(FramesAcc)};
8689
build_content_frames(SizeAcc, FramesAcc, FragSizeRem, FragAcc,
8790
Frags, BodyPayloadMax, ChannelInt)
8891
when FragSizeRem == 0 orelse Frags == [] ->

test/unit_SUITE.erl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
-include_lib("eunit/include/eunit.hrl").
2222

2323
-include("rabbit_memory.hrl").
24+
-include("rabbit.hrl").
2425

2526
-compile(export_all).
2627

@@ -42,7 +43,8 @@ groups() ->
4243
encrypt_decrypt_term,
4344
version_equivalence,
4445
pid_decompose_compose,
45-
platform_and_version
46+
platform_and_version,
47+
frame_encoding_does_not_fail_with_empty_binary_payload
4648
]},
4749
{parse_mem_limit, [parallel], [
4850
parse_mem_limit_relative_exactly_max,
@@ -388,6 +390,21 @@ version_equivalence(_Config) ->
388390
false = rabbit_misc:version_minor_equivalent(<<"3.0.0">>, <<"3.1.0">>),
389391
false = rabbit_misc:version_minor_equivalent(<<"3.0.0.1">>, <<"3.1.0.1">>).
390392

393+
frame_encoding_does_not_fail_with_empty_binary_payload(_Config) ->
394+
[begin
395+
Content = #content{
396+
class_id = 60, properties = none, properties_bin = <<0,0>>, protocol = rabbit_framing_amqp_0_9_1,
397+
payload_fragments_rev = P
398+
},
399+
ExpectedFrames = rabbit_binary_generator:build_simple_content_frames(1, Content, 0, rabbit_framing_amqp_0_9_1)
400+
end || {P, ExpectedFrames} <- [
401+
{[], [[<<2,0,1,0,0,0,14>>,[<<0,60,0,0,0,0,0,0,0,0,0,0>>,<<0,0>>],206]]},
402+
{[<<>>], [[<<2,0,1,0,0,0,14>>,[<<0,60,0,0,0,0,0,0,0,0,0,0>>,<<0,0>>],206]]},
403+
{[<<"payload">>], [[<<2,0,1,0,0,0,14>>,[<<0,60,0,0,0,0,0,0,0,0,0,7>>,<<0,0>>],206],
404+
[<<3,0,1,0,0,0,7>>,[<<"payload">>],206]]}
405+
]],
406+
ok.
407+
391408
set_stats_interval(Interval) ->
392409
application:set_env(rabbit, collect_statistics, coarse),
393410
application:set_env(rabbit, collect_statistics_interval, Interval).

0 commit comments

Comments
 (0)