aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_http2.erl
diff options
context:
space:
mode:
authorPablo Polvorin <[email protected]>2016-10-06 17:30:14 -0300
committerLoïc Hoguin <[email protected]>2016-10-09 00:35:53 +0200
commiteb9b69d1db4378ee1f191f069b689d02705b8be3 (patch)
tree82d846594cc7f5747ebe3eebe691a7ed5450569a /src/cow_http2.erl
parentbafd37c5968e684d63e61e68071b5e86ebfe7e9a (diff)
downloadcowlib-eb9b69d1db4378ee1f191f069b689d02705b8be3.tar.gz
cowlib-eb9b69d1db4378ee1f191f069b689d02705b8be3.tar.bz2
cowlib-eb9b69d1db4378ee1f191f069b689d02705b8be3.zip
Fix HTTP/2 parsing of WINDOW_UPDATE frames
Fix for cases where the full frame is not received in one go.
Diffstat (limited to 'src/cow_http2.erl')
-rw-r--r--src/cow_http2.erl9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/cow_http2.erl b/src/cow_http2.erl
index c2dba8b..555dfc2 100644
--- a/src/cow_http2.erl
+++ b/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)'};
parse(<< 4:24, 8:8, _:9, StreamID:31, _:1, Increment:31, Rest/bits >>) ->
{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)'};
%%
%% CONTINUATION frames.
@@ -240,6 +240,13 @@ parse_ping_test() ->
{ok, {ping, 1234567890}, <<>>} = parse(Ping),
{ok, {ping, 1234567890}, << 42 >>} = parse(<< Ping/binary, 42 >>),
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.
parse_fin(0) -> nofin;