[erlang-bugs] binary_to_term--are these bugs?
Matthias Lang
matthias@REDACTED
Fri Jan 18 12:22:21 CET 2008
Most of your examples seem to say that appending extra data to the end
of something which was produced by term_to_binary() doesn't upset
binary_to_term().
That came up on the mailing list recently:
http://www.erlang.org/pipermail/erlang-bugs/2007-November/000507.html
The last example is different, i.e.
> <<131,67,0>>
> '_'
> [<<131,100,0,1,95>>]
67 is an ERL_CACHED_ATOM whereas 100 is an ERL_ATOM_EXT, which are two
different ways of representing the same thing, though the former has
some undesirable properties (tm), which is probably why
term_to_binary() won't generate it for you.
Matthias
======================================================================
John Hughes writes:
> I've found some behaviour that I didn't expect in binary_to_term in R12B.
> I'm testing the QuickCheck property
>
>
>
> prop_binary_to_term() ->
>
> ?FORALL(Bin,binary(),
>
> case catch binary_to_term(Bin) of
>
> {'EXIT',{badarg,_}} ->
>
> true;
>
> Term ->
>
> Bins = term_to_binaries(Term),
>
> ?WHENFAIL(io:format("~p~n~p~n",[Term,Bins]),
>
> lists:any(fun(Bin2)->Bin=:=Bin2
> end,Bins))
>
> end).
>
>
>
> term_to_binaries(T) ->
>
> lists:usort([term_to_binary(T,[{compressed,Level},{minor_version,Ver}])
>
> || Level <- lists:seq(0,9),
>
> Ver <- [0,1]]).
>
>
>
> binary() ->
>
> ?LET(L,list(choose(0,255)),
>
> list_to_binary(L)).
>
>
>
> The property says that any binary that binary_to_term successfully decodes,
> must be an encoding of that term using some compression level and minor
> version (the encoding options mentioned in the documentation). But it fails,
> on, for example:
>
>
>
> <<131,97,0,0>>
>
> 0
>
> [<<131,97,0>>]
>
>
>
> Or
>
>
>
> <<131,106,0>>
>
> []
>
> [<<131,106>>]
>
>
>
> Or
>
>
>
> <<131,106,191,1,69,44,184,180,64>>
>
> []
>
> [<<131,106>>]
>
>
>
> Or
>
>
>
> <<131,67,0>>
>
> '_'
>
> [<<131,100,0,1,95>>]
>
>
>
> where the output in each case is the binary, the term it decodes to, and the
> list of all possible encodings produced by term_to_binary.
>
>
>
> Is this a bug?
>
>
>
> John
More information about the erlang-bugs
mailing list