From b7ae1f55199b8e7057e991874b6cafa065f159b0 Mon Sep 17 00:00:00 2001 From: Pablo Polvorin Date: Thu, 6 Oct 2016 17:12:52 -0300 Subject: Fix parsing of HTTP/2 PING frames Fix for cases where the full frame is not received in one go. --- src/cow_http2.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cow_http2.erl b/src/cow_http2.erl index a0d1297..c2dba8b 100644 --- a/src/cow_http2.erl +++ b/src/cow_http2.erl @@ -196,7 +196,7 @@ parse(<< 8:24, 6:8, _:7, 0:1, _:1, 0:31, Opaque:64, Rest/bits >>) -> {ok, {ping, Opaque}, Rest}; parse(<< 8:24, 6:8, _:104, _/bits >>) -> {connection_error, protocol_error, 'PING frames MUST NOT be associated with a stream. (RFC7540 6.7)'}; -parse(<< _:24, 6:8, _/bits >>) -> +parse(<< Len:24, 6:8, _/bits >>) when Len =/= 8 -> {connection_error, frame_size_error, 'PING frames MUST be 8 bytes wide. (RFC7540 6.7)'}; %% %% GOAWAY frames. @@ -233,6 +233,15 @@ parse(<< Len:24, 9:8, _:5, FlagEndHeaders:1, _:3, StreamID:31, HeaderBlockFragme parse(_) -> more. +-ifdef(TEST). +parse_ping_test() -> + Ping = ping(1234567890), + _ = [more = parse(binary:part(Ping, 0, I)) || I <- lists:seq(1, byte_size(Ping) - 1)], + {ok, {ping, 1234567890}, <<>>} = parse(Ping), + {ok, {ping, 1234567890}, << 42 >>} = parse(<< Ping/binary, 42 >>), + ok. +-endif. + parse_fin(0) -> nofin; parse_fin(1) -> fin. -- cgit v1.2.3