[erlang-bugs] bug in binary_to_term
Joe Armstrong
erlang@REDACTED
Thu Nov 22 14:24:45 CET 2007
-module(bug).
-compile(export_all).
%% If you do B = term_to_binary(Term)
%% and then concatinate some extra data to the end of
%% B then binary_to_term of the new binary succeeds
%% It should fail.
%%
%% You need to test that you have consumed the entire binary
%% when doing binary_to_term
%%
%% This caused a nasty error - when two TCP packets
%% became merged into one (due to packet fragmentation and recombiation)
%% each packet had one term, so the second term mysteriously vanished
test() ->
B = term_to_binary({hello,joe}),
{hello,joe} = binary_to_term(B),
B1 = <<"any old junk">>,
B2 = <<B/binary,B1/binary>>,
{hello,joe} = binary_to_term(B2), %% <--- this should raise an exception
this_should_not_be_printed_out.
/Joe Armstrong
More information about the erlang-bugs
mailing list