[BUG] erlang:decode_packet/3 generates corrupt header names with httph_bin

Will <>
Sun Mar 21 00:11:11 CET 2010


Hello,

erlang:decode_packet/3 generates strange corrupted header names for
unknown header types when using the httph_bin option. The cause seems
related to the length of the header name, short ones work fine.

Test Case:

test() ->
    B = <<
         "X-Transaction: 1269062039-39495-905\r\n"
         "X-RateLimit-Limit: 150\r\n"
         "Content-Type: application/json; charset=utf-8\r\n"
         "X-Foo: bar\r\n"
         "\r\n"
         >>,
    {ok, Headers, Rest} = decode_headers(B, []),
    io:format("HEADERS:~n~p~n", [Headers]),
    io:format("REST:~n~p~n", [Rest]).

decode_headers(Bin, Acc) ->
    case erlang:decode_packet(httph_bin, Bin, []) of
        {ok, {http_header, _N, _Name, _, _V} = H, Rest} ->
            decode_headers(Rest, [H | Acc]);
        {ok, http_eoh, Rest} ->
            {ok, Acc, Rest}
    end.

Result:

Erlang R13B04 (erts-5.7.5) [source] [smp:2:2] [rq:2] [async-threads:0]
[hipe] [kernel-poll:false]

HEADERS:
[{http_header,0,<<"X-Foo">>,undefined,<<"bar">>},
 {http_header,42,'Content-Type',undefined,
              <<"application/json; charset=utf-8">>},
 {http_header,0,
              <<88,45,70,111,111,50,14,0,64,190,14,1,10,0,0,0,14>>,
              undefined,<<"150">>},
 {http_header,0,
              <<88,45,70,111,111,50,14,0,64,190,14,1,10>>,
              undefined,<<"1269062039-39495-905">>}]
REST:
<<>>


More information about the erlang-bugs mailing list