Skip to content

Commit 926b97b

Browse files
Merge pull request #16081 from rabbitmq/mergify/bp/v4.2.x/pr-16079
AMQP 0-9-1: refactor command assembler (backport #16076) (backport #16079)
2 parents 56763e3 + 8d9c236 commit 926b97b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

deps/rabbit_common/src/rabbit_command_assembler.erl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
-type state() ::
3636
{'method', protocol()} |
3737
{'content_header', method(), class_id(), protocol()} |
38-
{'content_body', method(), body_size(), class_id(), protocol()}.
38+
{'content_body', method(), body_size(), content(), protocol()}.
3939

4040
-spec analyze_frame(frame_type(), binary(), protocol()) ->
4141
frame() | 'heartbeat' | 'error'.
@@ -85,9 +85,17 @@ process({content_header, ClassId, 0, 0, PropertiesBin},
8585
Content = empty_content(ClassId, PropertiesBin, Protocol),
8686
{ok, Method, Content, {method, Protocol}};
8787
process({content_header, ClassId, 0, BodySize, PropertiesBin},
88-
{content_header, Method, ClassId, Protocol}) ->
88+
{content_header, Method, ClassId, Protocol})
89+
when BodySize =< ?MAX_MSG_SIZE ->
8990
Content = empty_content(ClassId, PropertiesBin, Protocol),
9091
{ok, {content_body, Method, BodySize, Content, Protocol}};
92+
process({content_header, ClassId, 0, BodySize, _PropertiesBin},
93+
{content_header, Method, ClassId, _Protocol}) when BodySize > ?MAX_MSG_SIZE ->
94+
{error, rabbit_misc:amqp_error(
95+
frame_error,
96+
"content body size ~B exceeds maximum allowed size ~B",
97+
[BodySize, ?MAX_MSG_SIZE],
98+
rabbit_misc:method_record_type(Method))};
9199
process({content_header, HeaderClassId, 0, _BodySize, _PropertiesBin},
92100
{content_header, Method, ClassId, _Protocol}) ->
93101
unexpected_frame("expected content header for class ~w, "
@@ -98,13 +106,21 @@ process(_Frame, {content_header, Method, ClassId, _Protocol}) ->
98106
"got non content header frame instead", [ClassId], Method);
99107
process({content_body, FragmentBin},
100108
{content_body, Method, RemainingSize,
101-
Content = #content{payload_fragments_rev = Fragments}, Protocol}) ->
109+
Content = #content{payload_fragments_rev = Fragments}, Protocol})
110+
when byte_size(FragmentBin) =< RemainingSize ->
102111
NewContent = Content#content{
103112
payload_fragments_rev = [FragmentBin | Fragments]},
104-
case RemainingSize - size(FragmentBin) of
113+
case RemainingSize - byte_size(FragmentBin) of
105114
0 -> {ok, Method, NewContent, {method, Protocol}};
106115
Sz -> {ok, {content_body, Method, Sz, NewContent, Protocol}}
107116
end;
117+
process({content_body, _FragmentBin},
118+
{content_body, Method, _RemainingSize, _Content, _Protocol}) ->
119+
{error, rabbit_misc:amqp_error(
120+
frame_error,
121+
"content body frame exceeds remaining content size",
122+
[],
123+
rabbit_misc:method_record_type(Method))};
108124
process(_Frame, {content_body, Method, _RemainingSize, _Content, _Protocol}) ->
109125
unexpected_frame("expected content body, "
110126
"got non content body frame instead", [], Method).

0 commit comments

Comments
 (0)