Browse Source

Fix HTTP/2 parsing of WINDOW_UPDATE frames

Fix for cases where the full frame is not received in one go.
Pablo Polvorin 8 years ago
parent
commit
eb9b69d1db
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/cow_http2.erl

+ 8 - 1
src/cow_http2.erl

@@ -218,7 +218,7 @@ parse(<< 4:24, 8:8, _:9, StreamID:31, _:1, 0:31, _/bits >>) ->
 	{stream_error, StreamID, protocol_error, 'WINDOW_UPDATE frames MUST have a non-zero increment. (RFC7540 6.9)'};
 	{stream_error, StreamID, protocol_error, 'WINDOW_UPDATE frames MUST have a non-zero increment. (RFC7540 6.9)'};
 parse(<< 4:24, 8:8, _:9, StreamID:31, _:1, Increment:31, Rest/bits >>) ->
 parse(<< 4:24, 8:8, _:9, StreamID:31, _:1, Increment:31, Rest/bits >>) ->
 	{ok, {window_update, StreamID, Increment}, Rest};
 	{ok, {window_update, StreamID, Increment}, Rest};
-parse(<< _:24, 8:8, _/bits >>) ->
+parse(<< Len:24, 8:8, _/bits >>) when Len =/= 4->
 	{connection_error, frame_size_error, 'WINDOW_UPDATE frames MUST be 4 bytes wide. (RFC7540 6.9)'};
 	{connection_error, frame_size_error, 'WINDOW_UPDATE frames MUST be 4 bytes wide. (RFC7540 6.9)'};
 %%
 %%
 %% CONTINUATION frames.
 %% CONTINUATION frames.
@@ -240,6 +240,13 @@ parse_ping_test() ->
 	{ok, {ping, 1234567890}, <<>>} = parse(Ping),
 	{ok, {ping, 1234567890}, <<>>} = parse(Ping),
 	{ok, {ping, 1234567890}, << 42 >>} = parse(<< Ping/binary, 42 >>),
 	{ok, {ping, 1234567890}, << 42 >>} = parse(<< Ping/binary, 42 >>),
 	ok.
 	ok.
+
+parse_windows_update_test() ->
+	WindowUpdate = << 4:24, 8:8, 0:9, 0:31, 0:1, 12345:31 >>,
+	_ = [more = parse(binary:part(WindowUpdate, 0, I)) || I <- lists:seq(1, byte_size(WindowUpdate) - 1)],
+	{ok, {window_update, 12345}, <<>>} = parse(WindowUpdate),
+	{ok, {window_update, 12345}, << 42 >>} = parse(<< WindowUpdate/binary, 42 >>),
+	ok.
 -endif.
 -endif.
 
 
 parse_fin(0) -> nofin;
 parse_fin(0) -> nofin;